-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Read-only Views composite key not working in Hibernate 4
PostPosted: Fri Aug 18, 2017 8:39 am 
Newbie

Joined: Fri Aug 18, 2017 7:37 am
Posts: 3
Presently, we are migrating from hibernate 2 to hibernate 4 , we are facing issues for duplicate keys.

In Hibernate 2 we have multiple rows with same composite key combination but still data is coming as its expected.

In Hibernate 4 we not getting results as expected , Its coming duplicate as multiple rows exists with same composite key combination.

I was wondering why Hibernate 2 not considering duplicate ids to refer the objects, and is there some configuration available in hibernate 4 which will help avoid duplication of data if rows have same IDs


Top
 Profile  
 
 Post subject: Re: Read only Views Don't have primary of composite key
PostPosted: Fri Aug 18, 2017 9:39 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The issue is too vague to provide the right answer. Check out this article for more details on how you should implement a Composite Key with JPA and Hibernate.

Now, you said that:

Quote:
In hibernate 2 we have multiple rows with the same composite key combination but still data is coming as its expected.


This cannot be true because the DB will not allow two rows with the same Primary Key. It's the C in ACID that prevents this from happening. Maybe you were not using a Composite Key in Hibernate 2, but a synthetic one, like an IDENTITY or a SEQUENCE-based one.


Top
 Profile  
 
 Post subject: Re: Read-only Views composite key not working in Hibernate 4
PostPosted: Sat Aug 19, 2017 9:49 am 
Newbie

Joined: Fri Aug 18, 2017 7:37 am
Posts: 3
Hi Vlad
Thanks For the quick reply ,
I agree with u that "This cannot be true because the DB will not allow two rows with the same Primary Key" , so the problem is that there is a existing database which can't be changed and there are no composite key and primary key constraints on Views.
In all preexisted hbm files, columns which are defined as id and composite id are not actually primary key and composite key in views.
In old set up with hibernate 2 the values are coming different for rows having same value for ID fields , but in my new set up with same hbm files first row is repeated for all records returned as all rows have same ID.


hence Wanted to know if there is any configuration that is done in hibernate 2 for this to happen ,which I missing. Secondly is that possible in hibernate 4

regards


Top
 Profile  
 
 Post subject: Re: Read-only Views composite key not working in Hibernate 4
PostPosted: Sat Aug 19, 2017 11:01 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Quote:
hence Wanted to know if there is any configuration that is done in hibernate 2 for this to happen ,which I missing. Secondly is that possible in hibernate 4


I'm not aware of any such setting. But then, it's not very clear what the problem is. I understand that you can't change the DB schema, but the read-only View still needs a unique identifier or a combination of columns so that you can reference each individual row. I'm not sure how Hibernate 2 worked, I've never actually used this very old version. But if you want to upgrade, you have to provide such a unique identifier.


Top
 Profile  
 
 Post subject: Re: Read-only Views composite key not working in Hibernate 4
PostPosted: Mon Aug 21, 2017 5:57 am 
Newbie

Joined: Fri Aug 18, 2017 7:37 am
Posts: 3
This would be a workable solution for my case : https://forum.hibernate.org/viewtopic.php?f=1&t=941182


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.