-->
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.  [ 3 posts ] 
Author Message
 Post subject: objects in natural-id compared based on column value- bug?
PostPosted: Fri May 28, 2010 10:30 am 
Newbie

Joined: Fri May 28, 2010 10:18 am
Posts: 2
I am using hibernate 3.2

I recently added a class which has an id with generator class="native" and also a native-id which is composed of a String, an Integer and a class "Encounter" (which is also, obviously persisted with Hibernate). The id of "Encounter" (the one that is in the natural-id of the first class) has String id which is generated by my code (using UUID from java).

There comes a point in the program in which hibernate wants to make sure I am not changing any values in this natural-id. In doing so it passes what I take to be the value it finds in the database, to the equals() method of the object of type "Encounter" that is in session. But it does not pass an Encounter to this method. It doesn't even pass an encounter proxy. It passes the String which is the id of the Encounter that is in the column of the table representing the first class.

here is a stack-trace I create I created to show where this is occurring:

class cast while checking Encounter equals. Encounter guid = 87a41e89-eea3-4e27-b7f8-7ecf400b618f
obj is class java.lang.String toString is 87a41e89-eea3-4e27-b7f8-7ecf400b618f
java.lang.Exception
at com.lickersoft.soap.persistent.Encounter.equals(Encounter.java:338)
at org.hibernate.util.EqualsHelper.equals(EqualsHelper.java:10)
at org.hibernate.type.AbstractType.isEqual(AbstractType.java:108)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:93)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:169)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

I was able to make it work by altering the equals method of Encounter to also accept a String object that is the id (i.e. UUID) of the encounter. It works fine.

My question is whether this is the expected behavior? Are you not supposed to use objects as part of natural-ids? Is this a bug that I should report?


Top
 Profile  
 
 Post subject: Re: objects in natural-id compared based on column value- bug?
PostPosted: Mon May 31, 2010 9:53 pm 
Newbie

Joined: Wed Jul 05, 2006 2:16 am
Posts: 6
This may be related to HHH-1574.

If memory serves me correctly I had to specify that my natural-id was mutable to get around the issue.


Top
 Profile  
 
 Post subject: Re: objects in natural-id compared based on column value- bug?
PostPosted: Mon May 31, 2010 10:02 pm 
Newbie

Joined: Fri May 28, 2010 10:18 am
Posts: 2
Yep, that looks like the same issue. My workaround was altering my equals method to allow comparison to the ID. Assuming no guid collisions it should work until they fix this. It's just good to know it's a known bug.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.