Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate with foreign key

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am having one table in which both the entities are foreign and no primary key is in the table so when i am mapping that table in the xml file its showing error so how can i do that using hql instead of native sql queries.
following is the code through native sql
bean classes




following is my dao class method in which i have used native sql query so the query which i have kept in bold that i have to used instead of native sql

mapping with the xml of cfg by calling that bean it is giving error as @id is not their in the bean class which is used to define primary key.
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, this here is what we call a relationship table and in Hibernate you don;t map relationship tables to entities

All you do is add a Many To Many relationship betweeen Employee and SKill entities. You don;t need to have an entity named entity_to_skill. Here's an example of a Many to many relationship

 
Dave Tolls
Ranch Hand
Posts: 2100
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayesh post covers the Hibernate side, but I just wanted to point out that that linking table does have (or should have) a primary key anyway. A composite one consisting of empid and skill id.
Doesn't make much sense allowing these to be mapped more than once.

But yes, this sort of relationship is Hibernates job.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.. Its working now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic