-->
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.  [ 10 posts ] 
Author Message
 Post subject: It was good before 3.6.0 broke it by HHH-2350 fix
PostPosted: Fri Nov 26, 2010 7:08 am 
Newbie

Joined: Fri Nov 26, 2010 6:48 am
Posts: 7
Hi,

After upgrading from 3.3.2.GA to 3.6.0.FINAL I get an error when trying to cascade save a many-to-many:

Code:
SEVERE: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.local.model.data.Chapter
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
   at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:265)
   at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:275)
   at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:295)
   at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3378)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:520)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:230)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)

Here are the definitions of the mappings and the tables:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="org.local.model.data">
   <class name="Chapter" table="chapters">
      <meta attribute="sync-DAO">false</meta>

      <id name="Id" type="integer" column="ID">
         <generator class="identity" />
      </id>

      <property name="Name" column="Name" type="string" not-null="true" length="45" />

      <set name="Categories" table="chapters_categories" lazy="false" cascade="all-delete-orphan" order-by="CategoryID">
         <key column="ChapterID" not-null="true" />
         <one-to-many class="org.local.model.data.ChapterCategory" />
      </set>
   </class>
</hibernate-mapping>

Code:
CREATE TABLE `chapters` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `Name` varchar(45) NOT NULL,
  `Rank` smallint(5) unsigned NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1;

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="org.local.model.data">
   <class name="ChapterCategory" table="chapters_categories">
      <meta attribute="sync-DAO">false</meta>
      <id name="Id" type="integer" column="ID">
         <generator class="identity" />
      </id>

      <many-to-one name="Chapter" class="Chapter" column="ChapterID" not-null="true" lazy="false" insert="false"
         update="false" />
      <many-to-one name="Category" class="Category" column="CategoryID" not-null="true" lazy="false" />

      <property name="QuestionCount" column="QuestionCount" type="short" not-null="true" />
   </class>
</hibernate-mapping>

Code:
CREATE TABLE `chapters_categories` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `ChapterID` int(10) unsigned NOT NULL,
  `CategoryID` int(10) unsigned NOT NULL,
  `QuestionCount` smallint(5) unsigned NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `chapter_category` (`ChapterID`,`CategoryID`),
  KEY `chapter` (`ChapterID`),
  KEY `category` (`CategoryID`),
  CONSTRAINT `category` FOREIGN KEY (`CategoryID`) REFERENCES `categories` (`ID`) ON UPDATE CASCADE,
  CONSTRAINT `chapter` FOREIGN KEY (`ChapterID`) REFERENCES `chapters` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1;

Initially I used for the many-to-many a composite element, but I needed an alias and I had to do it this way.

I looked at the release notes between these 2 versions, but I didn't find the change that causes the problem.

Any ideas? Any fixes?

Thanks & best regards,
Dumi.


Last edited by dban on Mon Dec 13, 2010 1:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it
PostPosted: Tue Nov 30, 2010 4:45 pm 
Newbie

Joined: Fri Nov 26, 2010 6:48 am
Posts: 7
Does anyone know at least how this is supposed to work? I mean, did it function correctly in 3.3.2.GA and at some point it got broken? Or it was broken in 3.3.2.GA and now it's fixed? I really need a solution and I want to know if the problem is in the Hibernate code or in the way I'm using Hibernate on this specific many-to-many implementation.

Thanks,
Dumi.


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it
PostPosted: Fri Dec 10, 2010 11:25 am 
Newbie

Joined: Fri Nov 26, 2010 6:48 am
Posts: 7
I've tried different releases and the problem was introduced in 3.5.5.Final. But I still don't know if it's a problem that was introduced or a bug that was fixed. I'm not able to associate this with anything from the 3.5.5 changelog. I'll look further into this, but if anyone can help, please do so.

Thanks,
Dumi.


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it
PostPosted: Mon Dec 13, 2010 10:33 am 
Newbie

Joined: Fri Nov 26, 2010 6:48 am
Posts: 7
Ok, I've found the change that affects my code. It was introduced in 3.5.5.Final and in 3.6.0.Beta2. With their previous versions, 3.5.4.Final and 3.6.0.Beta1 my code runs just fine. The change is in ManyToOneType class,in isAlwaysDirtyCheck method, which is called from isDirty method. Initially it looked like this:
Code:
   public boolean isAlwaysDirtyChecked() {
      // If we have <tt>not-found="ignore"</tt> association mapped to a
      // formula, we always need to dirty check it, so we can update the
      // second-level cache
      return ignoreNotFound;
   }

and now it looks like this:
Code:
public boolean isAlwaysDirtyChecked() {
      // always need to dirty-check, even when non-updateable;
      // this ensures that when the association is updated,
      // the entity containing this association will be updated
      // in the cache
      return true;
   }

I can also break my code with the previous versions if I add the not-found="ignore" on this:
Code:
<many-to-one name="Chapter" class="Chapter" column="ChapterID" not-null="true" lazy="false" insert="false"
         update="false" not-found="ignore" />


Is this a bug or not?

Thanks & best regards,
Dumi.


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it by HHH-2350 fix
PostPosted: Mon Dec 13, 2010 1:42 pm 
Newbie

Joined: Fri Nov 26, 2010 6:48 am
Posts: 7
And the change was made when fixing HHH-2350:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2350

Is the fix correct?

Thanks & best regards,
Dumi.


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it by HHH-2350 fix
PostPosted: Fri Dec 17, 2010 4:02 pm 
Newbie

Joined: Fri Dec 17, 2010 11:14 am
Posts: 11
My identical transient object issue occurs on a many-to-one with a formula defined. Any suggested workarounds?


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it by HHH-2350 fix
PostPosted: Wed Apr 20, 2011 8:26 am 
Newbie

Joined: Wed Apr 20, 2011 8:19 am
Posts: 1
Dumi,

Did you find a suitable workaround for this issue?

Regards
Jesper


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it by HHH-2350 fix
PostPosted: Fri Jul 08, 2011 2:58 am 
Newbie

Joined: Fri Nov 26, 2010 6:48 am
Posts: 7
Finally I've managed to fix this problem. It looks like the parent was still transient when the child was saved, even if I was trying to save the parent. The following change - cascade="all" - was needed:
Code:
      <many-to-one name="Chapter" class="Chapter" column="ChapterID" not-null="true" lazy="false" insert="false"
         update="false" cascade="all" />


Dumi.


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it by HHH-2350 fix
PostPosted: Fri Jul 08, 2011 3:07 am 
Newbie

Joined: Fri Nov 26, 2010 6:48 am
Posts: 7
Or not... The parent is added twice in the database.


Top
 Profile  
 
 Post subject: Re: It was good before 3.6.0 broke it by HHH-2350 fix
PostPosted: Thu Feb 16, 2012 11:35 am 
Newbie

Joined: Thu Oct 05, 2006 3:26 am
Posts: 8
This may be related to this bug : https://hibernate.onjira.com/browse/HHH-5908


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