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

HibernateTemplate Composite Key fetching value null

 
Nirmal Jatania
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hello All...

I have one table that has composite key 'rid' and 'sid'.

For that i have made following beans to map with hibernate annotations :



WBListPK.java has following code :



My WBListDao has following method :

//Some other code ...
public WBList getWBListById(WBListPK wbListPK) {
return (WBList) this.hibernateTemplate.get(WBList.class,wbListPK);
}

Following is my controller code :



When I am executing above code, the wbList fetching the null value..

If anybody have any solutions, please help..

Thanks in advance...
 
hildich kilal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you having @JoinColumn annotation. You dont need it in defining primary key (composite in your case). That is to define relationships among tables.
Remove that annotation.and try.
 
Nirmal Jatania
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
himanshu Kapil wrote:Why are you having @JoinColumn annotation. You dont need it in defining primary key (composite in your case). That is to define relationships among tables.
Remove that annotation.and try.


Thanks for your reply.. Himanshu... I have tried your suggestion, but still i am getting null only..
 
hildich kilal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see how the getById is implemented in yuor that processor class. Also (though you might have already checked) please check if you have data in table with those id values.

or try some thing like this
entityManager.getEntityById(<class>m<idClassObject>)

 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

While we design the Database, sometimes the circumstance force us to create composite key..
if it is implemented in only JDBC, of course i think it doesn't matter...
but while it is implemented in ORM, yes, of course i think it doesn't matter also..
but it use more complex task..
i think its better to keep only one Key while we use ORM..
of course this is make simpler task..

Please correct me if i'm wrong..

Thanks..
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic