• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rows repetition problem

 
Dhiraj Srivastava
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have an id property that is not unique; does your table have a primary key?
 
Dhiraj Srivastava
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...

Thanks.. Its working..

Regards,

Dhiraj..
 
Dhiraj Srivastava
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic