Hi All
I have seen this issue alot through a day's searching but no solution to my issue. I am using DB2 and running a webapp in tomcat that uses hibernate
I am getting the above error and eventually got round to turning on the DB2 driver trace
The SQL that appears to be causing the issue isn't actually from one of the tables I have set up (all id's we wish to increment have sequences defined which is what is picked up in hibernate via
Code:
@SequenceGenerator(name="EnvironmentProperty_Gen", sequenceName="environment_property_sequence")
@Id @GeneratedValue(generator="EnvironmentProperty_Gen", strategy=GenerationType.AUTO)
In this case the offending table seems to be one hibernate creates itself. The SQL from the trace is
Code:
insert
into
SessionInfo
(id, lastModificationDate, rulesByteArray, startDate, OPTLOCK)
values
(default, ?, ?, ?, ?)
I am not sure how hibernate is choosing to get a value for id (by using default it suggests that some other DB2 object (e.g. a trigger) should do this
snip of my persistence.xml are here
Code:
<class>org.drools.persistence.session.SessionInfo</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
<!-- Leveraging an interceptor for auditing information -->
<property name="hibernate.ejb.interceptor" value="com.mycompany.myapplication.domain.common.AuditInterceptor" />
and some of my webApplication.xml
Code:
<property name="driverProperties">
<props>
<prop key="user">${myapplication.datasource.username}</prop>
<prop key="password">${myapplication.datasource.password}</prop>
<prop key="serverName">localhost</prop>
<prop key="portNumber">50000</prop>
<prop key="driverType">4</prop>
<prop key="databaseName">rd_db</prop>
<prop key="traceDirectory">c:\\temp</prop>
<prop key="traceFile">trace</prop>
<prop key="traceFileAppend">false</prop>
<prop key="traceLevel">-1</prop>
</props>
I am using type4 DB2XADataSource driver
And the stack trace is as follows
Code:
[Thread-12][2011-10-06 18:07:49,894] DEBUG: com.mycompany.myapplication.service.drools.bpm.BPMEngineImpl:startSession - Drools Environment Created.
[Thread-12][2011-10-06 18:07:50,012] DEBUG: org.hibernate.SQL:logStatement -
insert
into
SessionInfo
(id, lastModificationDate, rulesByteArray, startDate, OPTLOCK)
values
(default, ?, ?, ?, ?)
[Thread-12][2011-10-06 18:07:50,072] DEBUG: com.mycompany.myapplication.repository.worktray.impl.WorkTrayRepositoryImpl:preDestroy - @PreDestroy: WorkTrayRepositoryImpl was destroyed for entity class: WorkTray.
[Thread-12][2011-10-06 18:07:50,073] DEBUG: com.mycompany.myapplication.repository.worktray.impl.WorkItemRepositoryImpl:preDestroy - @PreDestroy: WorkItemRepositoryImpl was destroyed for entity class: WorkItem.
[Thread-12][2011-10-06 18:07:50,073] DEBUG: com.mycompany.myapplication.repository.snapshot.impl.SnapshotRepositoryImpl:preDestroy - @PreDestroy: SnapshotRepositoryImpl was destroyed for entity class: Snapshot.
[Thread-12][2011-10-06 18:07:50,074] DEBUG: com.mycompany.myapplication.repository.orchestration.impl.OrchestrationRepositoryImpl:preDestroy - @PreDestroy: OrchestrationRepositoryImpl was destroyed for entity class: Orchestration.
[Thread-12][2011-10-06 18:07:50,074] DEBUG: com.mycompany.myapplication.repository.lease.impl.PaymentRepositoryImpl:preDestroy - @PreDestroy: PaymentRepositoryImpl was destroyed for entity class: Payment.
[Thread-12][2011-10-06 18:07:50,075] DEBUG: com.mycompany.myapplication.repository.lease.impl.LeaseCostRepositoryImpl:preDestroy - @PreDestroy: LeaseCostRepositoryImpl was destroyed for entity class: LeaseCost.
[Thread-12][2011-10-06 18:07:50,075] DEBUG: com.mycompany.myapplication.repository.file.impl.PropertyFileRepositoryImpl:preDestroy - @PreDestroy: PropertyFileRepositoryImpl was destroyed for entity class: PropertyFile.
[Thread-12][2011-10-06 18:07:50,076] DEBUG: com.mycompany.myapplication.repository.event.impl.EventRecordRepositoryImpl:preDestroy - @PreDestroy: EventRecordRepositoryImpl was destroyed for entity class: EventRecord.
[Thread-12][2011-10-06 18:07:50,076] DEBUG: com.mycompany.myapplication.repository.deploymentplan.impl.DeploymentPlanRepositoryImpl:preDestroy - @PreDestroy: DeploymentPlanRepositoryImpl was destroyed for entity class: DeploymentPlan.
[Thread-12][2011-10-06 18:07:50,077] DEBUG: com.mycompany.myapplication.repository.deploy.impl.WorkflowItemRepositoryImpl:preDestroy - @PreDestroy: WorkflowItemRepositoryImpl was destroyed for entity class: WorkflowItem.
[Thread-12][2011-10-06 18:07:50,078] DEBUG: com.mycompany.myapplication.repository.deploy.impl.URLLibraryRepositoryImpl:preDestroy - @PreDestroy: URLLibraryRepositoryImpl was destroyed for entity class: URLLibrary.
[Thread-12][2011-10-06 18:07:50,078] DEBUG: com.mycompany.myapplication.repository.deploy.impl.URLEndpointRepositoryImpl:preDestroy - @PreDestroy: URLEndpointRepositoryImpl was destroyed for entity class: URLEndpoint.
[Thread-12][2011-10-06 18:07:50,079] DEBUG: com.mycompany.myapplication.repository.deploy.impl.TopicRepositoryImpl:preDestroy - @PreDestroy: TopicRepositoryImpl was destroyed for entity class: Topic.
[Thread-12][2011-10-06 18:07:50,079] DEBUG: com.mycompany.myapplication.repository.deploy.impl.SoftwareVersionRepositoryImpl:preDestroy - @PreDestroy: SoftwareVersionRepositoryImpl was destroyed for entity class: SoftwareVersion.
[Thread-12][2011-10-06 18:07:50,080] DEBUG: com.mycompany.myapplication.repository.deploy.impl.SoftwareRepositoryImpl:preDestroy - @PreDestroy: SoftwareRepositoryImpl was destroyed for entity class: Software.
[Thread-12][2011-10-06 18:07:50,081] DEBUG: com.mycompany.myapplication.repository.deploy.impl.ServerResourceRepositoryImpl:preDestroy - @PreDestroy: ServerResourceRepositoryImpl was destroyed for entity class: ServerResource.
[Thread-12][2011-10-06 18:07:50,081] DEBUG: com.mycompany.myapplication.repository.deploy.impl.ServerProcessRepositoryImpl:preDestroy - @PreDestroy: ServerProcessRepositoryImpl was destroyed for entity class: ServerProcess.
[Thread-12][2011-10-06 18:07:50,082] DEBUG: com.mycompany.myapplication.repository.deploy.impl.QueueRepositoryImpl:preDestroy - @PreDestroy: QueueRepositoryImpl was destroyed for entity class: Queue.
[Thread-12][2011-10-06 18:07:50,083] DEBUG: com.mycompany.myapplication.repository.deploy.impl.ProcessPortRepositoryImpl:preDestroy - @PreDestroy: ProcessPortRepositoryImpl was destroyed for entity class: ProcessPort.
[Thread-12][2011-10-06 18:07:50,083] DEBUG: com.mycompany.myapplication.repository.deploy.impl.JmsLibraryRepositoryImpl:preDestroy - @PreDestroy: JmsLibraryRepositoryImpl was destroyed for entity class: AbstractJMSLibrary.
[Thread-12][2011-10-06 18:07:50,084] DEBUG: com.mycompany.myapplication.repository.deploy.impl.FrameRepositoryImpl:preDestroy - @PreDestroy: FrameRepositoryImpl was destroyed for entity class: Frame.
[Thread-12][2011-10-06 18:07:50,084] DEBUG: com.mycompany.myapplication.repository.deploy.impl.FrameManagerRepositoryImpl:preDestroy - @PreDestroy: FrameManagerRepositoryImpl was destroyed for entity class: FrameManager.
[Thread-12][2011-10-06 18:07:50,085] DEBUG: com.mycompany.myapplication.repository.deploy.impl.EnvironmentPropertyRepositoryImpl:preDestroy - @PreDestroy: EnvironmentPropertyRepositoryImpl was destroyed for entity class: EnvironmentProperty.
[Thread-12][2011-10-06 18:07:50,085] DEBUG: com.mycompany.myapplication.repository.deploy.impl.EnvironmentInstallationRepositoryImpl:preDestroy - @PreDestroy: EnvironmentInstallationRepositoryImpl was destroyed for entity class: EnvironmentInstallation.
[Thread-12][2011-10-06 18:07:50,086] DEBUG: com.mycompany.myapplication.repository.deploy.impl.DeploymentRequestRepositoryImpl:preDestroy - @PreDestroy: DeploymentRequestRepositoryImpl was destroyed for entity class: JPADeploymentRequest.
[Thread-12][2011-10-06 18:07:50,086] DEBUG: com.mycompany.myapplication.repository.deploy.impl.DeployableComponentRepositoryImpl:preDestroy - @PreDestroy: DeployableComponentRepositoryImpl was destroyed for entity class: DeployableComponent.
[Thread-12][2011-10-06 18:07:50,087] DEBUG: com.mycompany.myapplication.repository.deploy.impl.DataSourceRepositoryImpl:preDestroy - @PreDestroy: DataSourceRepositoryImpl was destroyed for entity class: DataSource.
[Thread-12][2011-10-06 18:07:50,088] DEBUG: com.mycompany.myapplication.repository.deploy.impl.DatabaseProviderRepositoryImpl:preDestroy - @PreDestroy: DatabaseProviderRepositoryImpl was destroyed for entity class: DatabaseProvider.
[Thread-12][2011-10-06 18:07:50,088] DEBUG: com.mycompany.myapplication.repository.deploy.impl.CollectionTypeRepositoryImpl:preDestroy - @PreDestroy: CollectionTypeRepositoryImpl was destroyed for entity class: CollectionType.
[Thread-12][2011-10-06 18:07:50,089] DEBUG: com.mycompany.myapplication.repository.deploy.environment.impl.EnvConfigPendingChangeRepositoryImpl:preDestroy - @PreDestroy: EnvConfigPendingChangeRepositoryImpl was destroyed for entity class: EnvConfigPendingChange.
[Thread-12][2011-10-06 18:07:50,089] DEBUG: com.mycompany.myapplication.repository.admin.impl.ServerRepositoryImpl:preDestroy - @PreDestroy: ServerRepositoryImpl was destroyed for entity class: Server.
[Thread-12][2011-10-06 18:07:50,090] DEBUG: com.mycompany.myapplication.repository.lease.impl.LeaseRepositoryImpl:preDestroy - @PreDestroy: LeaseRepositoryImpl was destroyed for entity class: Lease.
[Thread-12][2011-10-06 18:07:50,091] DEBUG: com.mycompany.myapplication.repository.admin.impl.ProjectRepositoryImpl:preDestroy - @PreDestroy: ProjectRepositoryImpl was destroyed for entity class: Project.
[Thread-12][2011-10-06 18:07:50,091] DEBUG: com.mycompany.myapplication.repository.deploy.impl.DeploymentComponentRepositoryImpl:preDestroy - @PreDestroy: DeploymentComponentRepositoryImpl was destroyed for entity class: DeploymentComponent.
[Thread-12][2011-10-06 18:07:50,092] DEBUG: com.mycompany.myapplication.repository.lease.impl.CostCenterRepositoryImpl:preDestroy - @PreDestroy: CostCenterRepositoryImpl was destroyed for entity class: CostCenter.
[Thread-12][2011-10-06 18:07:50,092] DEBUG: com.mycompany.myapplication.repository.admin.impl.InstanceRepositoryImpl:preDestroy - @PreDestroy: InstanceRepositoryImpl was destroyed for entity class: Instance.
[Thread-12][2011-10-06 18:07:50,093] DEBUG: com.mycompany.myapplication.repository.admin.impl.EnvironmentRepositoryImpl:preDestroy - @PreDestroy: EnvironmentRepositoryImpl was destroyed for entity class: Environment.
[Thread-12][2011-10-06 18:07:50,097] DEBUG: com.mycompany.myapplication.repository.security.impl.UserGroupRepositoryImpl:preDestroy - @PreDestroy: UserGroupRepositoryImpl was destroyed for entity class: UserGroup.
[Thread-12][2011-10-06 18:07:50,098] DEBUG: com.mycompany.myapplication.repository.security.impl.UserGroupGroupRepositoryImpl:preDestroy - @PreDestroy: UserGroupGroupRepositoryImpl was destroyed for entity class: UserGroupGroup.
[Thread-12][2011-10-06 18:07:50,099] DEBUG: com.mycompany.myapplication.repository.security.impl.GroupRepositoryImpl:preDestroy - @PreDestroy: GroupRepositoryImpl was destroyed for entity class: Group.
[Thread-12][2011-10-06 18:07:50,099] DEBUG: com.mycompany.myapplication.repository.security.impl.UserRepositoryImpl:preDestroy - @PreDestroy: UserRepositoryImpl was destroyed for entity class: User.
[Thread-12][2011-10-06 18:07:50,100] DEBUG: com.mycompany.myapplication.repository.security.impl.UserDetailRepositoryImpl:preDestroy - @PreDestroy: UserDetailRepositoryImpl was destroyed for entity class: UserDetail.
[Thread-12][2011-10-06 18:07:50,101] DEBUG: com.mycompany.myapplication.repository.security.impl.GroupMemberRepositoryImpl:preDestroy - @PreDestroy: GroupMemberRepositoryImpl was destroyed for entity class: GroupMember.
[Thread-12][2011-10-06 18:07:50,102] DEBUG: com.mycompany.myapplication.repository.security.impl.GroupAuthorityRepositoryImpl:preDestroy - @PreDestroy: GroupAuthorityRepositoryImpl was destroyed for entity class: GroupAuthority.
[Thread-12][2011-10-06 18:07:50,102] DEBUG: com.mycompany.myapplication.repository.security.impl.UserAuthorityRepositoryImpl:preDestroy - @PreDestroy: UserAuthorityRepositoryImpl was destroyed for entity class: UserAuthority.
[Thread-12][2011-10-06 18:07:50,103] DEBUG: com.mycompany.myapplication.repository.user.impl.UserContextRepositoryImpl:preDestroy - @PreDestroy: UserContextRepositoryImpl was destroyed for entity class: UserContext.
[Thread-12][2011-10-06 18:07:50,404] ERROR: org.springframework.web.context.ContextLoader:initWebApplicationContext - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bpmEngine': Invocation of init method failed; nested exception is java.lang.RuntimeException: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1413)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:315)
at java.util.concurrent.FutureTask.run(FutureTask.java:150)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:736)
Caused by:
java.lang.RuntimeException: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
at com.mycompany.myapplication.service.drools.bpm.BPMEngineImpl.startSession(BPMEngineImpl.java:133)
at com.mycompany.myapplication.service.drools.bpm.BPMEngineImpl.initialize(BPMEngineImpl.java:81)
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 org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:340)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:293)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)
... 22 more
Caused by:
java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
at org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:137)
at org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:61)
at org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:109)
at com.mycompany.myapplication.service.drools.bpm.BPMEngineImpl.startSession(BPMEngineImpl.java:165)
at com.mycompany.myapplication.service.drools.bpm.BPMEngineImpl.createNewSession(BPMEngineImpl.java:139)
at com.mycompany.myapplication.service.drools.bpm.BPMEngineImpl.startSession(BPMEngineImpl.java:129)
... 30 more
Caused by:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:44)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:516)
at org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:123)
... 35 more
Caused by:
java.lang.RuntimeException: Could not commit session
at org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:135)
... 40 more
Caused by:
javax.persistence.PersistenceException: org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1174)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:674)
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 org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
at $Proxy53.persist(Unknown Source)
at org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:124)
... 40 more
Caused by:
org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity(IdentifierGeneratorHelper.java:84)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:98)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:800)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:774)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:778)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:668)
... 47 more
Finally, really sorry if this is nothing to do with Hibernate, I suspect might be a drools thing too but at my wits end now.
Cheers
Rob