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

Clarification while retrieving data from datbase

 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In my sample program I tried to retrieve set of records from my database using the below statements. I am successful with retrieving data from database.



I added up a unique id generator in the entity constructor.



Whenever session.createQuery("from Personal p") is invoked it calls up the constructor and it generates a new unique ID. wherein it should not be generated.

I am not sure where I have to specify the newly generated unique identifier for the primary_key

Can any one specify how to minimize/solve the problem
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could generate and assign it in your DAO rather than in your pojo. Or you could leave it to Hibernate to do.
 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I have tried the same with assigning it to DAO but it results with an error. Where it looks that a primary key must be assigned before invoking a session object or executing a createQuery().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic