-->
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.  [ 1 post ] 
Author Message
 Post subject: Foreign Keys Not Created
PostPosted: Fri Feb 16, 2007 7:05 am 
Beginner
Beginner

Joined: Tue May 09, 2006 2:30 am
Posts: 22
Hi !

I'm quite new to EJB3, Hibernate annotations and Hibernate entityManager and I'm having a problem making hibernate generate foreign keys when mapping relations.

I've create 2 relations, many-to-one and many-to-many, and neither cause a foreign key to be created !

My entity looks like that :

Code:
@Entity
@Table(name = "test_user")
public class TestUserH implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;
  @Column(nullable = false)
  private String  login;
  @Column(nullable = false)
  private String password;
  @ManyToMany(targetEntity=TestRoleH.class,
              cascade={CascadeType.PERSIST, CascadeType.MERGE}
  )
  @JoinTable(name="test_user_role",
             joinColumns={@JoinColumn(name="user_id")},
             inverseJoinColumns={@JoinColumn(name="role_id")}
  )
  private Set roles;
  @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
  @ForeignKey(name="fk_role")
//  @JoinColumn(name="role_id")
  private TestRoleH role;

// Nothing interessant from here...
}


And TestRoleH :

Code:
@SuppressWarnings("serial")
@Entity
@Table(name = "test_role")
public class TestRoleH implements Serializable {
  public static final String DEFAULT_ROLE_GROUP = "Roles";
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;
  @Column(nullable = false)
  private String  name;
  @Column(nullable = false, name="group_name")
  private String  group;
  @ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE},
              mappedBy="roles",
              targetEntity=TestUserH.class
  )
  private Set users;

// Nothing interessant from here...
}


hbm2ddl is configured as 'update'.

I'm using Hibernate 3.2.2 with PostgreSQL 8.2 under JBoss 4.0.5

Thanks for your help !

--
CĂ©line[/code]


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

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.