-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate/spring transaction problem [seeking immediate help
PostPosted: Fri Feb 20, 2009 7:00 pm 
Feb 20, 2009 3:45:12 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 2291, SQLState: 23000
Feb 20, 2009 3:45:12 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-02291: integrity constraint (REFDAT.XFK_DOCMDLVRFNDOCS_TO_DOCMDLVR) violated - parent key not found

Feb 20, 2009 3:45:12 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 2291, SQLState: 23000
Feb 20, 2009 3:45:12 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-02291: integrity constraint (REFDAT.XFK_DOCMDLVRFNDOCS_TO_DOCMDLVR) violated - parent key not found

Feb 20, 2009 3:45:12 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:606)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy11.saveDocDlvr(Unknown Source)
at com.msf.dvd.business.dao.DocDeliveryDAOTestCase.testSaveDocDlvr(DocDeliveryDAOTestCase.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (REFDAT.XFK_DOCMDLVRFNDOCS_TO_DOCMDLVR) violated - parent key not found

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10720)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 34 more


have one-to many relationship with parent table like
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name="parent_ID" )

saving record in DAO with
parent.setChild(<childlist>)
save(parent);

in applicationContext.xml file set
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>


<bean id="transactionAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<value>
save*=PROPAGATION_REQUIRED,-HibernateException
*=PROPAGATION_REQUIRED, readOnly
</value>
</property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="hibernateTransactionManager"/>
</property>
<property name="transactionAttributeSource">
<ref bean="transactionAttributes"/>
</property>
</bean>

[I am getting parent insert statement first then all child insert statements but failed when saving with one transaction. Any help on this matter will be highly appreciated.
Seeking immediate solution]


Top
  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 9:30 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Can you post a bit more of the code and the sql generated by it?

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject: HI
PostPosted: Mon Feb 23, 2009 4:32 pm 
Here is how I map my entity with JPA annotations

In parent

@OneToMany(cascade =CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "ID" , nullable=false, insertable= false, updatable = false)
[getter n setter for child]


In child
@ManytoOne
[getter n setter for parent]

now i want to save parent n child record at a time
I am doing
parent.addChild(<childlist>)

and it raise this error..I think parent is not persisted while saving child

or may be you guys can point me in right direction


Top
  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 4:51 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Looking at the code and mapping details you posted I dont see any issues. The only thing I could think of is the:
@JoinColumn(name = "ID" , nullable=false, insertable= false, updatable = false)
which you have specified in the onetomany mapping.

Are you sure the foreign key column of child table referencing parent table is ID?

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject: Re: HI
PostPosted: Tue Feb 24, 2009 5:07 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 8:25 am
Posts: 46
Location: Saint Petersburg, Russian Federation
rupal82 wrote:
...

now i want to save parent n child record at a time
I am doing
parent.addChild(<childlist>)

and it raise this error..I think parent is not persisted while saving child

or may be you guys can point me in right direction


Why do you use @JoinColumn at all? You can use just a @OneToMany and @ManyToOne mappings. Another note is that you didn't define inverted association end:

Code:
@Entity
public class Parent {

    @Id
    @GeneratedValue
    private Long id;

    @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY, mappedBy = "parent")
    private List<Child> childs;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Child> getChilds() {
        return childs;
    }

    public void setChilds(List<Child> childs) {
        this.childs = childs;
        for (Child child : childs) {
            child.setParent(this);
        }
    }
}


Code:
@Entity
public class Child {

    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne
    private Parent parent;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Parent getParent() {
        return parent;
    }

    public void setParent(Parent parent) {
        this.parent = parent;
    }
}


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