• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Query Question

 
Mirrell Knabe
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am relatively new to using hibernate...Is it possible to invoke a query returning multiple rows WITH THE SAME PRIMARY KEY into a list object?....I have tried many things, but keep getting an error that multiple rows are being returned with the same identifier...but, that is what I need returned...Any help or suggestions would greatly be appreciated!
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means that the column in the database that you've marked as primary key in your hibernate mapping is not actually a primary key or is your query such that redundant rows are generated??
 
Mirrell Knabe
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit....my query is such that redundant primary keys are generated(returned)...that is what I want...the other row data is unique...for example..

Primary Key Sample Row Field
000001 000001
000001 000002
000001 000003
...etc

Is it not possible to return multiple rows with non-unique primary keys?
 
R George
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think it really make sense when you say multiple rows are returned with same primary key. In relational database, a primay key is meant for uniquely identifying a row/record. In case one key is not able to identify a record uniquely, a combination of keys are used(composite key).

And ideally each table should have a primary/composite key in a relational DB.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. "non-unique primary key" is an oxymoron. Have a search through this forum for questions about data modelled without a proper primary key. This sort of question gets asked a lot and the pros and cons of doing this have been discussed many times before.
 
Sachin Kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen the scenario when it happens after a join query. But I never get exception. Have you checked your mapping your case looks to be of one-to-many mapping and also tru putting logical equal and hashcode method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic