Showing results for 
Search instead for 
Did you mean: 


Former Member
0 Kudos

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos


I tried to use relations between CMP-EntityBeans.

A relation of type 1:1 works fine.

But using a 1:N relation causes me problems:

- I defined the methods in the bean-class with the parameter-type "Collection"

- I defined the relation in ejb-jar.xml

- I defined the binding in persistent.xml


I can call the method "Collection getXY()" and I get the corresponding elements; this is OK.

If I have defined "cascading delete" in the relation, the childs are deleted as well; this is OK.

PROBLEM: I want to add an element to the Collection, I do something like this:

  MyBeanLocal myBean = myBeanLocalHome.findByPrimaryKey(KEY_A);

  MyChildLocal myChild = myChildLocalHome.findByPrimaryKey(KEY_B);

  Collection childsOfMyBean = myBean.getMyChilds();


then I can do:

  myBean = myBeanLocalHome.findByPrimaryKey(KEY_A);

  childsOfMyBean = myBean.getMyChilds();

and wihtin this Collection, the new inserted child exists, this seems OK.

BUT: In the database, the entry is not made persistent;

Any idea?

Thanks, Josef

0 Kudos

Hi Josef,

it seems that this is a transaction boundaries problem. All updates made on the persistent entity objects are visible in the cache and are not visible in the database. I will explain in detail how the caching mechanism for the CMP entity beans works.

1. Every peristent entity is loaded from the database just once - the first time it is accessed by a transaction.

2. If a persisntent object is changed by a transaction it is stored in the database at the end of the transaction (again with a single database operation although the transaction may have performed a sequence of changes on that entity).

In your case I would propose to define a business method (may be in a session bean) that performs the update (the first four lines of code) and make it in a single transaction. The easiest way to do that is to declare a container managed transaction attribute "Required" or "Requires new". When that business methd ends, the transaction will commit and the persistent cache will be flushed into the database.



Former Member
0 Kudos

Hi Svetoslav,

I have exactly the same problem!

Unfortunately the problem persists:

1. if i use "Required" I get some concurrency exception (which makes no sense to me, because the calls are relate not related (timely)

2. if i use "Not supported" I get the "caching behaviour" (modifications not in DB)

3. if i use "Requires New" the method doesn't seem to return any results (im gonna investigate this case further soon..)

Im gonna do some more research - but maybe anyone of you has already figured this issue out completely...

Thanks a lot!