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.