Thread: Player xferring

Page 4 of 4 FirstFirst ... 234
Results 31 to 36 of 36
  1. #31  
    Registered Member
    Join Date
    Dec 2013
    Posts
    318
    Thanks given
    109
    Thanks received
    72
    Rep Power
    309
    Quote Originally Posted by clem585 View Post
    I'm not sure how complex types are handled. Let's say you have:

    Code:
    public class Player extends Entity {
    
    private Inventory inventory;
    
    }
    How does this get mapped internally in the DB with hibernate? Wouldn't it be 2 tables?
    No, you have to annotate the fields that map to a column in a table.

    e.g.

    Code:
    @Entity
    @Table(name = "players")
    public class Player {
        @Id
        @Column(name = "id")
        private long id;
    
        @Column(name = "username")
        private String username;
    
        /* your normal code that isn't persistence */
        private Inventory inventory;
    
        public Player() { /* empty constructor for hibernate */ }
    
        /* your normal code */
        public Inventory getInventory() { return inventory; }
        public void setInventory(Inventory inventory) { this.inventory = inventory; }
    
        /* setters and getters are required by hibernate */
        public long getId() { return id; }
        public void setId(long id) { this.id = id; }
        public String getUsername() { return username; }
        public void setUsername(String username) { this.username = username; }
    }
    Now if you want to store your items in a table you can...


    Code:
    @Entity
    @Table(name = "inventory")
    public class Inventory {
     // ... code similar to above but for inventory ...
    }
    and then construct everything:

    Code:
    Player player = HibernateUtil.getPlayer(id);
    player.setInventory(HibernateUtil.getInventory(player));
    But you don't need to have a separate table for your inventory. If you want to, you can, you should.
    Reply With Quote  
     

  2. Thankful user:


  3. #32  
    Registered Member
    Join Date
    May 2012
    Posts
    947
    Thanks given
    19
    Thanks received
    27
    Rep Power
    0
    can anyone help me with this i tried that code but account doesnt have the vars its in player.java so how would i go about casting player to account. or if anyone can help me add me on discord. Blacksabath#4272
    Reply With Quote  
     

  4. #33  
    Registered Member
    Join Date
    May 2012
    Posts
    947
    Thanks given
    19
    Thanks received
    27
    Rep Power
    0
    anyone?
    Reply With Quote  
     

  5. #34  
    Registered Member
    Join Date
    May 2012
    Posts
    947
    Thanks given
    19
    Thanks received
    27
    Rep Power
    0
    anyone?
    Reply With Quote  
     

  6. #35  
    Registered Member
    Join Date
    Nov 2012
    Posts
    523
    Thanks given
    12
    Thanks received
    49
    Discord
    View profile
    Rep Power
    26
    Tbh i have a suggestion, its the most horrible method especially if there is alot of accounts, if you are xfering frm old server base to a new 1, id just say manuqlly login to each account and just add items,xp n etc manually.
    Reply With Quote  
     

  7. #36  
    Registered Member
    Join Date
    May 2012
    Posts
    947
    Thanks given
    19
    Thanks received
    27
    Rep Power
    0
    anyone?
    Reply With Quote  
     

Page 4 of 4 FirstFirst ... 234

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Are YOU a Player Mod for RuneScape?
    By ιаυяа in forum Voting
    Replies: 156
    Last Post: 06-23-2008, 11:03 PM
  2. Custom Player Title's
    By Dune in forum Tutorials
    Replies: 43
    Last Post: 09-03-2007, 11:34 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •