• Post Reply Bookmark Topic Watch Topic
  • New Topic

mapping for duplicate rows

 
vamshidhar nimbagiri
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
here in my case the table contains duplicate rows, so how can i do hibernate mapping file for that table where rows can be duplicated.
one more thing, if the table contains timestamp as a field does it help?
It would be appreciated if any body give me solution to handle this problem.

Thanks in advance,
vamshidhar nimbagiri
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you usually will have a primary key that is always unique. Then just map it like any other table would be mapped.

Mark
 
vamshidhar nimbagiri
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Mark,
But here in my case i dont have any primary key, there may be chance of
more than two rows with same values i mean duplicate rows.
but for mapping hibernate requires one primary key,
could you please tell me how to overcome this problem? is there any other way of doing this?

Thanks
vamshi
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some database engines like Oracle have add a hidden column to every table that uniquely identifies each row in the table. Oracle calls it rowid. This column is always there and is independent of any primary key you may have defined.

create table table1
(
col1 int not null
);

select col1, rowid
from table1;

You could map that column as your primary key.

As for the timestamp column, you can use that as a primary key only if it's guaranteed to be unique.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But here in my case i dont have any primary key, there may be chance of
more than two rows with same values i mean duplicate rows.
but for mapping hibernate requires one primary key,
could you please tell me how to overcome this problem? is there any other way of doing this


For data to be relational an identifier is mandatory, otherwise it is not relational data. This is your problem: you can't expecte an Object Relational Mapping tool to work when the relational side is not relational. Its not just Hibernate that requires a primary key, the data requires it too. You can work round the lack of a primary key by defining a composite key that includes every field in the table, but this is not a fix, and you should only do this if you absolutely cannot change the data model. The only real fix is to properly define your table (by adding a primary key) before trying to get it to work with an ORM product.
 
vamshidhar nimbagiri
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all of you.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!