[Hibernate-JIRA] Created: (HHH-5299) Multi-Level cascading of unsaved instances with bidirectional associations fails with TransientObjectException
by Carl-Eric Menzel (JIRA)
Multi-Level cascading of unsaved instances with bidirectional associations fails with TransientObjectException
--------------------------------------------------------------------------------------------------------------
Key: HHH-5299
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5299
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Environment: Tested with OracleXE and H2DB, Hibernate Core 3.3.2, Hibernate Entity Manager 3.4.0
Reporter: Carl-Eric Menzel
Priority: Critical
Attachments: 0001-fixed-no-cascading-check-to-also-accept-entities-wit.patch, cascadetest.zip
Given the following classes (pseudocode, full source in the attached zipfile):
Top {
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "top")
List<Middle> middles
}
Middle {
@ManyToOne
Top top
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "BOTTOM_ID")
Bottom bottom
}
Bottom {
@OneToOne(mappedBy = "bottom")
Middle middle
}
The following code fails on the second flush with a TransientObjectException:
Top top = new Top();
em.persist(top);
em.flush();
// top is now attached, status MANAGED
Middle middle = new Middle(1l);
middle.setBottom(new Bottom());
top.addMiddle(middle);
Middle middle2 = new Middle(2l);
middle2.setBottom(new Bottom());
top.addMiddle(middle2);
// both middles and bottoms are transient but should be saved by cascade
em.flush(); // boom!
The relevant part of the error is:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: test.Bottom.middle -> test.Middle
at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:376)
at org.hibernate.engine.Cascade.cascade(Cascade.java:163)
The same code works without exception when using EclipseLink instead of Hibernate EntityManager, so I am assuming that the test code is valid.
Some debugging revealed that CascadingAction.PERSIST_ON_FLUSH.noCascade() checks the inverse association from Bottom to Middle. It then calls a private method isInManagedState to verify that this association does not reference an unsaved instance. It does this by checking the entities EntityEntry.getStatus() value, which it expects to be MANAGED or READ_ONLY. At this time, however, the Middle instance is in the middle (no pun intended) of its own cascading save cycle and therefore its status is SAVING. This, to me, seems to be a valid session-attached status, so isInManagedState() should also accept this state.
The attached patch against Hibernate Core 3.3.2 implements just that, and this change makes the above example code work as expected. The Hibernate test suite did not complain, so I am reasonably sure I did not break anything else.
See also the attached cascadetest.zip for a ready-to-use testcase that demonstrates the error with Hibernate Core 3.3.2. Change the dependency in the supplied pom.xml to a patched version of Hibernate Core, and the test will no longer fail.
Carl-Eric Menzel
C1 SetCon GmbH
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 10 months
[Hibernate-JIRA] Created: (HHH-5429) [regression] unable to persist entity using derby 10.6.1.0 and hibernate 3.5+
by Max Giesbert (JIRA)
[regression] unable to persist entity using derby 10.6.1.0 and hibernate 3.5+
-----------------------------------------------------------------------------
Key: HHH-5429
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5429
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.0.Beta1, 3.5.4, 3.5.3
Environment: derby 10.6.1.0 and hibernate 3.5+
Reporter: Max Giesbert
when inserting any kind of entity
@Entity
public class TestObject
{
private Long id;
private String test;
public TestObject(){}
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getId()
{
return id;
}
[...]
i get the following error message
org.hibernate.exception.ConstraintViolationException: could not insert: [com.mypackage.TestObject]
>>java.sql.SQLIntegrityConstraintViolationException: Column 'ID' cannot accept a NULL value.
>>org.apache.derby.impl.jdbc.EmbedSQLException: Column 'ID' cannot accept a NULL value.
>>ERROR 23502: Column 'ID' cannot accept a NULL value.
>> at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
>> at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeColumn(Unknown Source)
>> at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeRow(Unknown Source)
>> at org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(Unknown Source)
>> at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown Source)
>>...
the same code is working fine with versions 3.3.2GA and annotations 3.4.0GA and earlier. i just switched back...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 10 months
[Hibernate-JIRA] Created: (JPA-4) PersistenceUtil.isLoaded() fails with a ClassCastException in Websphere 7
by Mike Youngstrom (JIRA)
PersistenceUtil.isLoaded() fails with a ClassCastException in Websphere 7
-------------------------------------------------------------------------
Key: JPA-4
URL: http://opensource.atlassian.com/projects/hibernate/browse/JPA-4
Project: Java Persistence API
Issue Type: Bug
Affects Versions: 1.0.0
Environment: Websphere 7 Hibernate 3.5
Reporter: Mike Youngstrom
To duplicate deploy a .war with hibernate 3.5 to Websphere with the contextlistener below. You need to set the classloader to "parent last" so that your application will use Hibernate's JPA 2 API instead of Webspheres JPA 1 API.
package test;
import javax.persistence.Persistence;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class TestListener implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("Result of isLoaded: "+Persistence.getPersistenceUtil().isLoaded(new Object()));
}
}
Throws the exception below.
It appears the problem is that PersistenceProviderResolverHolder.PersistenceProviderResolverPerClassLoader scans all of the classloader levels to find PersistenceProviders. This is finding Websphere's OpenJPA provider in a different classloader than the application and hence with a different JPA API. Although this example happens in Websphere 7 it would in theory also happen anytime Websphere is used in an app server with another JPA implementation that cannot be removed from the server.
java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider
at javax.persistence.Persistence$1.isLoaded(Persistence.java:92)
at test.TestListener.contextInitialized(TestListener.java:20)
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1681)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:374)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:299)
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:100)
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:166)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:731)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:616)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:376)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:668)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1122)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1315)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:623)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:940)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:725)
at com.ibm.ws.runtime.component.ApplicationMgrImpl$1.run(ApplicationMgrImpl.java:1266)
at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:4509)
at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:4687)
at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1271)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2043)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:439)
at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:382)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:653)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:615)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:37)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:244)
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1086)
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:967)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:848)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:773)
at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1320)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1213)
at com.ibm.ws.management.application.sync.StartDeploymentTask.startDeployment(StartDeploymentTask.java:236)
at com.ibm.ws.management.application.sync.StartDeploymentTask.fullAppUpdate(StartDeploymentTask.java:113)
at com.ibm.ws.management.application.sync.StartDeploymentTask.performTask(StartDeploymentTask.java:101)
at com.ibm.ws.management.application.sync.AppBinaryProcessor$ExpandApp.expand(AppBinaryProcessor.java:1556)
at com.ibm.ws.management.application.sync.AppBinaryProcessor.postProcessSynchronousExt(AppBinaryProcessor.java:654)
at com.ibm.ws.management.bla.sync.BLABinaryProcessor.postProcess(BLABinaryProcessor.java:569)
at com.ibm.ws.management.bla.sync.BLABinaryProcessor.onChangeCompletion(BLABinaryProcessor.java:451)
at com.ibm.ws.management.repository.FileRepository.postNotify(FileRepository.java:1915)
at com.ibm.ws.management.repository.FileRepository.update(FileRepository.java:1424)
at com.ibm.ws.management.repository.client.LocalConfigRepositoryClient.update(LocalConfigRepositoryClient.java:189)
at com.ibm.ws.sm.workspace.impl.WorkSpaceMasterRepositoryAdapter.update(WorkSpaceMasterRepositoryAdapter.java:655)
at com.ibm.ws.sm.workspace.impl.RepositoryContextImpl.update(RepositoryContextImpl.java:1954)
at com.ibm.ws.sm.workspace.impl.RepositoryContextImpl.synch(RepositoryContextImpl.java:1902)
at com.ibm.ws.sm.workspace.impl.WorkSpaceImpl.synch(WorkSpaceImpl.java:511)
at com.ibm.ws.management.configservice.ConfigServiceImpl.save(ConfigServiceImpl.java:703)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:37)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:244)
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1086)
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:967)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:848)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:773)
at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1320)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1213)
at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181)
at com.ibm.ws.management.connector.rmi.RMIConnectorService.invoke(RMIConnectorService.java:282)
at com.ibm.ws.management.connector.rmi._RMIConnectorService_Tie.invoke(_RMIConnectorService_Tie.java:395)
at com.ibm.ws.management.connector.rmi._RMIConnectorService_Tie._invoke(_RMIConnectorService_Tie.java:160)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:622)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:475)
at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2841)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2714)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 10 months