-->
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.  [ 4 posts ] 
Author Message
 Post subject: 'constraint violated' problem during saving via cascade
PostPosted: Wed Feb 03, 2010 12:16 pm 
Newbie

Joined: Wed Mar 08, 2006 11:12 am
Posts: 16
Hi,
we are facing following problem and are not able to solve it.
we have to entities in 1:N relationship mapped in following way:

Code:
@Entity
PartnerExport {

  @OneToMany(targetEntity = MarkedExport.class, cascade=CascadeType.ALL, mappedBy = "export")
  private Set<MarkedExport> marks = new HashSet<MarkedExport>(0);
....
}

@Entity
MarkedExport {

  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name = "PARTNEREXPORT_ID", insertable = false, updatable = false)
  private PartnerExport export;
...
}


and we add MarkedExport instance into collection 'marks' and also register PartnerExport to MarkedExport.
Code:
PartnerExport export = new PartnerExport();
MarkedExport mark = new MarkedExport();
export.getMarks().add(mark);
mark.setExport(export);


now we need to save 'export' entity (using merge or persist), but we are getting following exception:

javax.resource.spi.LocalTransactionException: ORA-02091: transaction rolled back
ORA-02291: integrity constraint (MARKEDEXPORT_PEXPORT_FK) violated - parent key not found
at com.sun.gjc.spi.LocalTransaction.commit(LocalTransaction.java:93)
at com.sun.enterprise.resource.ConnectorXAResource.commit(ConnectorXAResource.java:114)
at com.sun.enterprise.distributedtx.J2EETransaction.commit(J2EETransaction.java:471)
at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.commit(J2EETransactionManagerOpt.java:371)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3817)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3596)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1379)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:205)



we really don't know what is wrong with our dependent object (MarkedExport) and why hibernate cannot fill foreign key, when saving both object via cascade.

thanx for hint


Top
 Profile  
 
 Post subject: Re: 'constraint violated' problem during saving via cascade
PostPosted: Thu Feb 04, 2010 5:04 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Unfortunately you don't report the full stacktrace, but apparently you use a container managed transactionfactory.
It is not clear to me if the commit is called implicitely with your save/persist action or if you call commit explicitely.
Anyway: before the commit you must also persist the mark entity.


Top
 Profile  
 
 Post subject: Re: 'constraint violated' problem during saving via cascade
PostPosted: Thu Feb 04, 2010 5:23 am 
Newbie

Joined: Wed Mar 08, 2006 11:12 am
Posts: 16
i do not call commit explicitly, it is called implicitly by merge action.

in detail code looks like following (hibernate + jpa)
Code:
public Object merge(Object object) {
  Object result = getSession().merge(object);
  getSession().flush();
  return result;
}

private Session getSession() {
   return ((EntityManagerImpl) entityManager.getDelegate()).getSession();
}


so, what i call as a persist operation is

Code:
PartnerExport export = new PartnerExport();
MarkedExport mark = new MarkedExport();
export.getMarks().add(mark);
mark.setExport(export);
merge(export);


Top
 Profile  
 
 Post subject: Re: 'constraint violated' problem during saving via cascade
PostPosted: Thu Feb 04, 2010 5:36 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
I oversight that you use CascadeType.ALL which includes also Cascade.PERSIST,
so in theory you don't need to call persist explicitly on the mark instance.

Anyway I suggest you to activate following log levels:

log4j.logger.org.hibernate.SQL=TRACE
log4j.logger.org.hibernate.type=TRACE

so we will see what is missing.


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