IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes Rows repetition problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Rows repetition problem" Watch "Rows repetition problem" New topic
Author

Rows repetition problem

Dhiraj Srivastava
Ranch Hand

Joined: Aug 29, 2001
Posts: 49
Hi,

I am getting following recrods from DB

Id Amount
1 400
2 0
3 500
3 250
3 1000

I want exact record in my Hibernate Query. But I Get

Id Amount
1 400
2 0
3 500
3 500
3 500

Value against the same Id (300) repeats every time. WHY ???

Thanks in advance
Dhiraj Srivastava
[ August 08, 2007: Message edited by: Mark Spritzler ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You seem to have an id property that is not unique; does your table have a primary key?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Dhiraj Srivastava
Ranch Hand

Joined: Aug 29, 2001
Posts: 49
Actually I fetching recrods from a View. I cannot use unique key here. Is this problem relates something with cache.

Thanks

Dhiraj Srivastava
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Actually I fetching recrods from a View. I cannot use unique key here. Is this problem relates something with cache.

No, this is not strictly a caching problem. ORM tools only work with relational data. A table or view without a primary key is not relational, so an ORM tool wont work with it. What is most likely happening is you are using a non-unique value for your identifier so Hibernate loads the first object with an id of 3 and any subsequent requests for an object of this type with this id gets the one Hibernate has already loaded. Fix this by giving your view a surrogate key.
Dhiraj Srivastava
Ranch Hand

Joined: Aug 29, 2001
Posts: 49
Hi...

Thanks.. Its working..

Regards,

Dhiraj..
Dhiraj Srivastava
Ranch Hand

Joined: Aug 29, 2001
Posts: 49
Hi,

Still I have major issue.

Consider Following Recrods

Id Amount
1 400
2 500
3 500
3 250
3 -

As In this table I don't have any unique combination. Even in composite key. Now I want all the records as it is.

Now if I put Id Column as primary key it will give:

Id Amount
1 400
2 500
3 500
3 500
3 500

500 will repeat in all the Id 3 records. And If put both of these coloumns in the <composite-id> tag I get the following records.

Id Amount
1 400
2 500
3 500
3 250

Now you can see last record is not coming. Becase Amount Value was null.

All I want the exact records in my Hibernate Query. As I get from SQL

I hope I am able to explain the problem clearly.

Regards,

Dhiraj Srivastava
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You can't use a composite key with a null value; keys can't contain nulls. If you want Hibernate to work with your view, give your view a surrogate key.
 
 
subject: Rows repetition problem
 
Threads others viewed
the most bizarre java error ever
Something fishy with catch block.......
try/catch??
i need help on java database arithemetic
The most bizarre java error ever
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture