• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting problems with foriegnkey

 
Prasath Premkumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,

I'm new to hibernate. I started working on a Spring + hibernate project recently. Since I'm new to hibernate, i reversed engineered the DAOs from the database and went through them. I have 2 tables named user_roles and users in my database and the user_role_id column of users table references id column of user_roles table. (Foreign key constraint).

In the Users.java class i had all the setter methods to create a user object but no setters for user_role_id, instead of that there was a setter method for UserRoles object. So i thought to create a UserRoles object and set it so it will lookup and automatically assigns the id, but when creating the UserRoles object i found that it requires Set<Users> collection to be set since of the many to one relation. Nw I'm really confused how to insert a user record since there is a cyclic dependency in the classes. (I dont know whether this is the correct way, but since these are generated classes i thought this is the standard way to follow.)

Can anybody guide me how to insert a user record with user_role_id???

According to the rules of javaranch, i hereby inform that cross posting of this question is occuring here
and since i didnt get any help there (till this post occured), i decided to post in javaranch.

Thanks in advance.
 
Prasath Premkumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Maybe my question is not clear to you all. In that case it will be much helpful if anyone can post me an example of how to insert values to a table which has foreignkey
reference from another table. I just want to find what is the best way to do it.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic