Two Laptop Bag
The moose likes Object Relational Mapping and the fly likes Hibernate Query Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Query Question" Watch "Hibernate Query Question" New topic

Hibernate Query Question

Mirrell Knabe
Ranch Hand

Joined: Oct 13, 2008
Posts: 32
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

Joined: Aug 03, 2008
Posts: 9465

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??

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Mirrell Knabe
Ranch Hand

Joined: Oct 13, 2008
Posts: 32
Hi 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

Is it not possible to return multiple rows with non-unique primary keys?
R George

Joined: Aug 10, 2009
Posts: 5
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

Joined: Apr 14, 2004
Posts: 10336

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.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sachin Kumar

Joined: Aug 31, 2008
Posts: 20
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.
I agree. Here's the link:
subject: Hibernate Query Question
It's not a secret anymore!