[Persistence, JBoss/CMP, Hibernate, Database] - OneToMany Relationship problem - BatchUpdate
by rabbiaqaswar
Hello
I am using NetBeans 5.5 and database is Oracle 9i.
There are two tables in my database
1. Department
Long DEPTID
VARCHAR DEPTNAME
2. Employee
Long EMPID
VARCHAR EMPNAME
LONG DEPTID
In the entity Department, I have:
| @OneToMany(cascade = CascadeType.ALL, mappedBy="department")
| private Set<Employee> empCollection;
|
| public Set<Employee> getEmployeeCollection() {
| return this.empCollection;
| }
|
| public void setEmployeeCollection(Set<Employee> empCollection) {
| this.empCollection= empCollection;
| }
|
|
In the Employee entity, I have
| @ManyToOne
| @JoinColumn(name = "DEPTID", referencedColumnName = "DEPTID", nullable= false)
| private Department department;
|
| public Department getDepartment() {
| return this.department;
| }
|
| public void setDepartment(Department department) {
| this.department = department;
| }
|
|
In my Stateful session, I have:
| public Long addEmployee(Long deptID, String empName) throws Exception
| {
| Department dept = em.find(Department.class, deptID);
| Employee empl = new Employee();
| empl.setName(empName);
| empl.setDepartment(dept);
| dept.getEmployeeCollection().add(empl);
| em.persist(empl);
| return empl.getEmpID();
| }
|
In the Client application having the main method if I call the addEmployee method once, it works fine. But if i call this method in a loop then it works once or twice and after that i start getting the following exception:
| java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=shaheen/22, BranchQual=, localId=22] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update)
| at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
| at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:297)
| at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
| at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
| at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
| at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
| at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
| at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
| at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
| at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:190)
| at org.jboss.remoting.Client.invoke(Client.java:525)
| at org.jboss.remoting.Client.invoke(Client.java:488)
| at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:78)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRemoteProxy.java:133)
| at $Proxy1.addEmployee(Unknown Source)
| at app.Main.main(Main.java:43)
| Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=shaheen/22, BranchQual=, localId=22] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update)
| at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
| at org.jboss.tm.TxManager.commit(TxManager.java:240)
| at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:297)
| at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
| at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
| at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
| at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
| at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
| at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
| at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
| Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (TESTDEV.FK_DEPARTMENT_EMPLOYEE) violated - parent key not found
|
| at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
| at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
| at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:517)
| at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
| at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
| ... 33 more
|
I have a container managed EntityManager in my session, maybe it is a transaction problem? The exception also says that parent key not found but the parent key exists in the database. Please help, I cannot find a solution.
Thanks
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4008794#4008794
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4008794
19 years, 2 months
[JBoss Portal] - Re: Upgrade from 2.4.1 SP1 to 2.6 - Big Effort?
by sjewett
anonymous wrote :
| The true test would be to create the content in a 2.4.1 instance in the database. Leaving the database as is, and loading the 2.6 portal instance. Your CMS content should stay in tact including versions etc.
|
| You can test this by navigating the content via the Content Admin tool on both instances. If you do, I would be interested to know what you find
|
I was confused, but I think I have figured out why. When working with 2.4.1, I had downloaded the zip file that has the AS bundled in. You have suggested that I leave the database as is and "load the 2.6 portal instance." I couldn't figure out how to do this. Can I load the 2.6 instance by copying the jboss-portal.sar directory from the 2.6 directories into the deploy dir of my bundled 2.4.1? Then it will work with my existing database (right?). (And when I start up the server, will it create the additional 2.6 tables that you mentioned?)
Thanks, Sohil. Please let me know if my current thinking is on track.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4008791#4008791
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4008791
19 years, 2 months