Discussion:
CMP2.0 persistence giving parent key not found exception: ORA-02291
(too old to reply)
Nary
2004-05-19 00:32:10 UTC
Permalink
I have two CMPs, Customer and ContactInfo, with ContactInfo having a FK relationship
with Customer. (ContactInfo table contains CustomerID).

Scenario 1: ejbPostCreate() of Customer entity bean has the code to create the
child object ContactInfo Scenario 2: Customer and ContactInfo are created explicitly
from the session bean.


In both scenarios, I'm getting the following exception: javax.ejb.EJBException:
nested exception is: java.sql.SQLException: ORA-02291: integrity constraint (CONTACTINFO_CUSTOMER_FK)
violated - parent key not found

It worked fine when I was using persistence type as 5.1.0. Getting this exception
once I moved to CMP2.x

Using CMP2.x but not CMR. Using default values in the deployment descriptors.
Using local interfaces for entity beans.

It's looks as if the container is waiting for the end of transaction before inserting
the customer in the DB but doing it in the wrong order. i.e., sending the insert
for contact info before the customer insert.

Any help is appreciated. Thanks in advance. Scenario 1 sample code and the exception
stack trace attached at bottom.

A session bean to create the customer has: #######################################
public CustomerVO createCustomer(CustomerVO customerVO) {

CustomerHome custHome = ... jndi lookup... Customer customerLocal = custHome.create(customerVO);
CustomerVO createdCustomer = customerLocal.getCustomer(); return createdCustomer;


} #######################################

Customer entity bean has: ####################################### public String
ejbCreate(CustomerVO customerVO) throws CreateException { // create a primary
key and set it setId(createUniqueKey()); // set the attributes of the Customer
here..... }

public void ejbPostCreate(CustomerVO customerVO) throws CreateException { ContactInfoHome
contactHome = ...jndi lookup... String customerId = (String) getEntityContext().getPrimaryKey();
contactHome.create(customerId, customerVO.getContactInfo()); } #######################################


ContactInfo entity bean has: ####################################### public String
ejbCreate(String customerId, ContactInfoVO contactInfoVO) throws CreateException
{ // create a primary key and set it setId(createUniqueKey()); setCustomerId(customerId);
//set the attributes of the ContactInfo here..... }

public void ejbPostCreate(String customerId, ContactInfoVO contactInfoVO) throws
CreateException { // empty method } #######################################

Exception stack trace: javax.ejb.EJBException: nested exception is: java.sql.SQLException:
ORA-02291: integrity constraint (CONTACTINFO_CUSTOMER_FK) violated - parent key
not found at oracle.jdbc.dbaccess.DBError.throwSqlException(Ljava.lang.String;Ljava.lang.String;I)V(DBError.java:170)
at oracle.jdbc.ttc7.TTIoer.processError()V(TTIoer.java:218) at oracle.jdbc.ttc7.Oall7.receive()V(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(BBI[B[Loracle.jdbc.dbaccess.DBType;[Loracle.jdbc.dbaccess.DBData;I[Loracle.jdbc.dbaccess.DBType;[Loracle.jdbc.dbaccess.DBData;I)V(TTC7Protocol.java:1427)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(Loracle.jdbc.dbaccess.DBStatement;B[BLoracle.jdbc.dbaccess.DBDataSet;ILoracle.jdbc.dbaccess.DBDataSet;I)I(TTC7Protocol.java:844)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(Z)V(OracleStatement.java:1722)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(Z)V(OracleStatement.java:1647)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout()V(OracleStatement.java:2167)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate()I(OraclePreparedStatement.java:404)
at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate()I(PreparedStatement.java:95)
at weblogic.ejb20.manager.BaseEntityManager.executeInsertStmt(Ljava.util.List;Ljavax.transaction.Transaction;Ljava.util.Set;Z)V(BaseEntityManager.java:546)
at weblogic.ejb20.manager.BaseEntityManager.executeDBOperations(Ljava.util.List;Ljavax.transaction.Transaction;Ljava.util.Set;ZI)V(BaseEntityManager.java:435)
at weblogic.ejb20.internal.TxManager$TxListener.executeDBOperations(Ljava.util.Set;ZI)V(TxManager.java:596)
at weblogic.ejb20.internal.TxManager$TxListener.executeDBOperationsDriver(Z)V(TxManager.java:571)
at weblogic.ejb20.internal.TxManager$TxListener.flushModifiedKeys()V(TxManager.java:768)
at weblogic.ejb20.internal.TxManager.flushModifiedBeans(Ljavax.transaction.Transaction;)V(TxManager.java:350)
at weblogic.ejb20.manager.BaseEntityManager.flushModifiedBeans(Ljavax.transaction.Transaction;)V(BaseEntityManager.java:2301)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.flushModifiedBeans()V(RDBMSPersistenceManager.java:2672)
at ContactInfoHome_shdy1d__WebLogic_CMP_RDBMS.ejbFindByCustomer(Ljava.lang.String;)Ljava.util.Collection;(ContactInfoHome_shdy1d__WebLogic_CMP_RDBMS.java:528)
at COM.jrockit.reflect.NativeMethodInvoker.invoke0(ILjava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Native
Method) at COM.jrockit.reflect.NativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown
Source) at COM.jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown
Source) at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown
Source) at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.collectionFinder(Ljavax.ejb.EntityBean;Ljava.lang.reflect.Method;[Ljava.lang.Object;)Ljava.util.Collection;(RDBMSPersistenceManager.java:342)
at weblogic.ejb20.manager.BaseEntityManager.collectionFinder(Ljavax.transaction.Transaction;Ljava.lang.reflect.Method;[Ljava.lang.Object;ZZ)Ljava.util.Collection;(BaseEntityManager.java:1655)
at weblogic.ejb20.manager.BaseEntityManager.collectionFinder(Lweblogic.ejb20.interfaces.InvocationWrapper;Ljava.lang.reflect.Method;[Ljava.lang.Object;)Ljava.util.Collection;(BaseEntityManager.java:1627)
at weblogic.ejb20.internal.EntityEJBLocalHome.finder(Lweblogic.ejb20.internal.MethodDescriptor;[Ljava.lang.Object;I)Ljava.lang.Object;(EntityEJBLocalHome.java:467)
at ContactInfoHome_shdy1d_LocalHomeImpl.findByCustomer(Ljava.lang.String;)Ljava.util.Collection;(ContactInfoInfoHome_shdy1d_LocalHomeImpl.java:124)
at CustomerSessionBeanHome_fq6t6h_ELOImpl.getCustomer()
thorick
2004-05-20 05:21:27 UTC
Permalink
Hi

I haven't had to chance to look at your example in detail (yet), but since release
6.0
the CMP DD has had a tag called:

<delay-database-insert-until>

if you have upgraded to a 6.x or later CMP DD, I'd try setting the value of
this tag to:

'ejbCreate'

if you want all inserted values to be reflected in the DB at the earliest time.

Hope this helps

thorick
Nary
2004-05-20 18:46:59 UTC
Permalink
I added this to the weblogic-cmp-rdbms-jar.xml:
<delay-database-insert-until>ejbCreate</delay-database-insert-until>

I'm still getting the same exception. The container is not executing the inserts.

Also, looking at the documentation,
"delay-database-insert-until element has an effect only when order-database-operations
is False.".
AND
"If enable-batch-operations is set to True, the container automatically sets order-database-operations
to True. To turn off order-database-operations, set both order-database-operations
and enable-batch-operations to False."

So it seems like I need to turn off all three flags to false. I still need to
do this and test it again, but is there any better way to tell the container to
execute the inserts in the right order?

thanks.
Post by thorick
Hi
I haven't had to chance to look at your example in detail (yet), but since release
6.0
<delay-database-insert-until>
if you have upgraded to a 6.x or later CMP DD, I'd try setting the value of
'ejbCreate'
if you want all inserted values to be reflected in the DB at the earliest time.
Hope this helps
thorick
Nary
2004-05-20 21:52:38 UTC
Permalink
Setting the below in weblogic-cmp-rdbms-jar.xml gives: <enable-batch-operations>False</enable-batch-operations>
<order-database-operations>False</order-database-operations>

I'm using <!DOCTYPE weblogic-rdbms-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic
8.1.0 EJB RDBMS Persistence//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'>


Is there a different DTD I need to use? thanks.


[ejbc] ERROR: Error from ejbc: [EJB:011019]While reading META-INF/weblogic-cmp-rdbms-jar.xml,
the persistence layer of the Entity EJB failed to deploy. The error was: [ejbc]
Error in descriptor line 43: Error parsing file at line: 43 column: 25. The content
of element type "weblogic-rdbms-bean" must match "(ejb-name,data-source-name,table-map+,field-group*,relationship-caching*,weblogic-query*,delay-database-insert-until?,use-select-for-update?,lock-order?,instance-lock-order?,automatic-key-generation?,check-exists-on-method?)"..



[ejbc] ERROR: ejbc couldn't invoke compiler
Post by Nary
<delay-database-insert-until>ejbCreate</delay-database-insert-until>
I'm still getting the same exception. The container is not executing the inserts.
Also, looking at the documentation,
"delay-database-insert-until element has an effect only when order-database-operations
is False.".
AND
"If enable-batch-operations is set to True, the container automatically
sets order-database-operations
to True. To turn off order-database-operations, set both order-database-operations
and enable-batch-operations to False."
So it seems like I need to turn off all three flags to false. I still need to
do this and test it again, but is there any better way to tell the container to
execute the inserts in the right order?
thanks.
Post by thorick
Hi
I haven't had to chance to look at your example in detail (yet), but since release
6.0
<delay-database-insert-until>
if you have upgraded to a 6.x or later CMP DD, I'd try setting the value of
'ejbCreate'
if you want all inserted values to be reflected in the DB at the earliest time.
Hope this helps
thorick
thorick
2004-05-20 23:33:14 UTC
Permalink
Hi

Before going any further I should note that 'order-database-operations' only works
if you are using container managed relationships (CMR). If one is not using
container managed relationships, then there is no way for the container to know
that there are foreign key dependencies between the different beans.
Nary
2004-05-21 19:26:50 UTC
Permalink
I'm in a bind now.
<delay-database-insert-until>ejbCreate</delay-database-insert-until> didn't work.
And yes, I'm not using CMR.

I also tried setting:
<delay-updates-until-end-of-tx>False</delay-updates-until-end-of-tx> in weblogic-ejb-jar.xml,

but this didn't go past ejbc. Gave me an error saying:
the <delay-updates-until-end-of-tx> tag is set to 'false'. This conflicts with
the default setting 'true' for tag <enable-batch-operations> and tag <order-database-operations>.
Either set <delay-updates-until-end-of-tx> to 'true', or set the other two tags
to 'false'.

And I can't set the order-database-operations or the other because, for one I'm
not using CMR and secondly, the DTD that I use for weblogic-cmp-rdbms-jar.xml
doesn't have these attributes.
http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'

So, what's my way out? I really need to get this out, but am blocked. thanks for
the help.
thorick
2004-05-23 01:11:16 UTC
Permalink
Hi

The 8.1 cmp dtd should have tags: order-database-operations and enable-batch-operations,
both of which we want to be set to 'False'. Are you specifying that you are
using the 810 dtd in your weblogic-cmp-rdbms.xml file, as in:

<!DOCTYPE weblogic-rdbms-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0
EJB RDBMS Persistence//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'>

?

for the docs on the 8.1 dtd see:

http://edocs.bea.com/wls/docs81/ejb/DDreference-cmp-jar.html


Also, if we cannot resolve this here, it sounds like you may want to open a case
with technical support to get dedicated help with your upgrade if you need it.

-thorick
Nary
2004-05-27 21:02:31 UTC
Permalink
Finally got it working. Thanks for your help. This is what I changed to get it
working (convert EB from 6.0 to 81). Not sure why the default value for <delay-database-insert-until>
changed to ejbPostCreate() in wls81.

#####################################################
I left the logic to create child objects in the post create method. This is what
I modified in the Deployment descriptors:

In weblogic-rdmbs-cmp-jar.xml:
1) Added under <weblogic-rdbms-bean> element:
<delay-database-insert-until>ejbCreate</delay-database-insert-until>
** This element is added only for those entity beans that have create child objects
logic in the ejbPostCreate() method.

2) Added under <weblogic-rdbms-jar> element:
<order-database-operations>False</order-database-operations>
<enable-batch-operations>False</enable-batch-operations>
** I was adding these under <weblogic-rdbms-bean> element causing the ejbc to
fail. Stupid mistake.

In weblogic-ejb-jar.xml
3) Added under <weblogic-enterprise-bean>/<entity-descriptor>/<persistence>:
<delay-updates-until-end-of-tx>True</delay-updates-until-end-of-tx>
**Don't know if this is really required. But added this anyway.
Post by thorick
Hi
The 8.1 cmp dtd should have tags: order-database-operations and enable-batch-operations,
both of which we want to be set to 'False'. Are you specifying that you are
<!DOCTYPE weblogic-rdbms-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0
EJB RDBMS Persistence//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'>
?
http://edocs.bea.com/wls/docs81/ejb/DDreference-cmp-jar.html
Also, if we cannot resolve this here, it sounds like you may want to open a case
with technical support to get dedicated help with your upgrade if you need it.
-thorick
ebi ugo
2004-09-20 14:51:23 UTC
Permalink
HELLO,
I'M DEVELOPING AN APP THAT'S USING A STATELESS SESSION BEAN(SERVICES LAYER). INSIDE THE BEAN, I HAVE A METHOD CALLED "USERCREATOR" THAT CALLS 2 CONTAINER MANAGED TX/PERSISTNCE ENTITY BEANS EJBCREATEs. ALL TRANSACTION ATTRIBUTES ARE SET TO TX_REQUIRED BOTH FOR THE SESSION AND ENTITY BEANS. THE PROBLEM I HAVE IS THAT THE METHOD "USERCREATOR" DOES NOT ROLLBACK THE 2 CREATED ENTITY BEANS, IF THERE IS A PROBLEM IN DE COURSE OF IT'S EXECUTION AS IT'S SUPPOSED TO. IT'S SOMETHING LIKE THIS
PUBLIC VOID USERCREATOR() THROWS MYEXCEPTION{
TRY{
CREATEENTITYA();
CREATEENTITYB();
}CATCH(EXCEPTION E){
CONTEXT.SETROLLBACKONLY();
THROW NEW MYEXCEPTION();
}//MYEXCEPTION IS AN APPLICATION EXCEPTION
}
IT SUCCESSFULLY ROLLS BACK CREATEENTITYB() BUT FAILS TO ROLLBACK CREATEENTITYA(). I'M USING WEBLOGIC 8.1 DEV EDITION SERVER AS THE SERVER. ANY HELP WILL BE HIGHLY APPRECIATED AS I'M UNDER PRESSURE TO DELIVER AS SOON AS POSSIBLE. THANX. BRIGHT, SYBASE
Andre Serodio
2005-01-26 13:16:55 UTC
Permalink
Could you please send me the entire archive for weblogic-cpms-jar.xml that works?
I've tried everything and it´s still not working.
Appreciate that.
Post by Nary
Finally got it working. Thanks for your help. This is
what I changed to get it
working (convert EB from 6.0 to 81). Not sure why the
default value for <delay-database-insert-until>
changed to ejbPostCreate() in wls81.
#####################################################
I left the logic to create child objects in the post
create method. This is what
<delay-database-insert-until>ejbCreate</delay-database
-insert-until>
** This element is added only for those entity beans
that have create child objects
logic in the ejbPostCreate() method.
<order-database-operations>False</order-database-opera
tions>
<enable-batch-operations>False</enable-batch-operation
s>
** I was adding these under <weblogic-rdbms-bean>
element causing the ejbc to
fail. Stupid mistake.
In weblogic-ejb-jar.xml
3) Added under
<weblogic-enterprise-bean>/<entity-descriptor>/<persis
<delay-updates-until-end-of-tx>True</delay-updates-unt
il-end-of-tx>
**Don't know if this is really required. But added
this anyway.
Post by thorick
Hi
order-database-operations and
d enable-batch-operations,
Post by thorick
both of which we want to be set to 'False'. Are
you specifying that
Post by thorick
you are
using the 810 dtd in your weblogic-cmp-rdbms.xml
<!DOCTYPE weblogic-rdbms-jar PUBLIC '-//BEA
Systems, Inc.//DTD WebLogic
Post by thorick
8.1.0
EJB RDBMS Persistence//EN'
'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms2
0-persistence-810.dtd'>
Post by thorick
?
http://edocs.bea.com/wls/docs81/ejb/DDreference-cmp-j
ar.html
Post by thorick
Also, if we cannot resolve this here, it sounds like
you may want to
Post by thorick
open a case
with technical support to get dedicated help with
your upgrade if you
Post by thorick
need it.
-thorick
Loading...