• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rows repetition problem

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...

Thanks.. Its working..

Regards,

Dhiraj..
 
Dhiraj Srivastava
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic