-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Unexpected FKs with hbm2ddl.auto=update
PostPosted: Sat Oct 18, 2008 10:43 pm 
Newbie

Joined: Fri Dec 14, 2007 3:08 pm
Posts: 3
I am getting some weird FKs created on my PlayableCharacter table. I'm using postgresql. Here's \d playablecharacter:

"fk8460341b2a06029f" FOREIGN KEY (id) REFERENCES playertype(id)
"fk8460341b32156bc3" FOREIGN KEY (playertype_id) REFERENCES playertype(id)
"fk8460341ba6595463" FOREIGN KEY (user_id) REFERENCES huser(id)
"fk8460341baf1e736f" FOREIGN KEY (id) REFERENCES huser(id)

Why would these two in bold be created?

Code:
@Entity
public class PlayableCharacter {

    private Integer id;
    private User user;
    private PlayerType playerType;


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @ManyToOne
    public PlayerType getPlayerType() {
        return playerType;
    }

    public void setPlayerType(PlayerType playerType) {
        this.playerType = playerType;
    }
}




@Table(name = "huser",
        uniqueConstraints = {
        @UniqueConstraint(columnNames={"username"}),
        @UniqueConstraint(columnNames={"email"})
                }
)
@Entity
@NamedQueries({@NamedQuery(name = "User.findByUsername",
        query = "FROM User WHERE username = :username")})
public class User {

    private Integer id;
    private String username;
    private String password;
    private boolean admin;
    private String email;
    private String currentContext;
    private List<PlayableCharacter> playableCharacters;


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(nullable = false)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(nullable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(nullable = false)
    public boolean isAdmin() {
        return admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }

    @Column(nullable = false)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCurrentContext() {
        return currentContext;
    }

    public void setCurrentContext(String currentMenus) {
        this.currentContext = currentMenus;
    }

    @OneToMany(mappedBy="id")
    public List<PlayableCharacter> getPlayableCharacters() {
        return playableCharacters;
    }

    public void setPlayableCharacters(List<PlayableCharacter> playableCharacters) {
        this.playableCharacters = playableCharacters;
    }
}





@Table(uniqueConstraints = {
        @UniqueConstraint(columnNames={"name"})
                }
)
@Entity
@NamedQueries({@NamedQuery(name = "PlayerType.findByName",
        query = "FROM PlayerType WHERE name = :name")})
public class PlayerType {

    private Integer id;
    private String name;
    private Integer hp;
    private Integer mp;
    private Integer strength;
    private Integer defense;
    private Integer dexterity;
    private Integer agility;
    private Integer intelligence;
    private Integer willpower;
    //TODO: add a requirement to use this PlayerType

    private List<PlayableCharacter> playableCharacters;

    public PlayerType() {
    }

    public PlayerType(String name, Integer hp, Integer mp, Integer strength, Integer defense, Integer dexterity, Integer agility, Integer intelligence, Integer willpower) {
        this.name = name;
        this.hp = hp;
        this.mp = mp;
        this.strength = strength;
        this.defense = defense;
        this.dexterity = dexterity;
        this.agility = agility;
        this.intelligence = intelligence;
        this.willpower = willpower;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(nullable = false)
    public Integer getHp() {
        return hp;
    }

    public void setHp(Integer hp) {
        this.hp = hp;
    }

    @Column(nullable = false)
    public Integer getMp() {
        return mp;
    }

    public void setMp(Integer mp) {
        this.mp = mp;
    }

    @Column(nullable = false)
    public Integer getStrength() {
        return strength;
    }

    public void setStrength(Integer strength) {
        this.strength = strength;
    }

    @Column(nullable = false)
    public Integer getDefense() {
        return defense;
    }

    public void setDefense(Integer defense) {
        this.defense = defense;
    }

    @Column(nullable = false)
    public Integer getDexterity() {
        return dexterity;
    }

    public void setDexterity(Integer dexterity) {
        this.dexterity = dexterity;
    }

    @Column(nullable = false)
    public Integer getAgility() {
        return agility;
    }

    public void setAgility(Integer agility) {
        this.agility = agility;
    }

    @Column(nullable = false)
    public Integer getIntelligence() {
        return intelligence;
    }

    public void setIntelligence(Integer intelligence) {
        this.intelligence = intelligence;
    }

    @Column(nullable = false)
    public Integer getWillpower() {
        return willpower;
    }

    public void setWillpower(Integer willpower) {
        this.willpower = willpower;
    }

    @OneToMany(mappedBy="id")
    public List<PlayableCharacter> getPlayableCharacters() {
        return playableCharacters;
    }

    public void setPlayableCharacters(List<PlayableCharacter> playableCharacters) {
        this.playableCharacters = playableCharacters;
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2008 10:54 pm 
Newbie

Joined: Fri Dec 14, 2007 3:08 pm
Posts: 3
OK I figured it out on my own. The problem was these: @OneToMany(mappedBy="id") I just removed the parameter completely and things worked.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.