-
Bug
-
Resolution: Done
-
Major
-
JBossAS-3.2.6 Final
-
None
I discovered strange change in the behaiviour of relation collections after jboss 3.2.3
Here is what I have as starting point:
I have 2 entity beans. the first one hase relation to the second one (one to many). The primary key for second bean cosits of 2 fields of type Integer and Long.
so I get an instance of the first bean and get a collection of releated instances of the second bean.
Collection c = bean1.getBean2();
c.clear;
PriamryKeyCalss pk = new PrimaryKeyClass();
pk.expiring = new Long(0);
for (int i = 0; i < newReleationIds.size(); i++) {
pk.id = (Integer)newReleationIds;
Bean2 bean2 = Bean2Home.findByPrimaryKey(pk);
c.add(bean2);
}
What I found is actually that wehn the bean2 instance is loaded from DB and not from the read-ahead cache everything is fine.
In case bean2 instance is loaded from read-ahead-cache the primary key object is reused and stored directly into new instance instead of creating new instance of the primary key object.
So when I change the value of the ID field find new instance in c.add there is a chekc which checks is this PK is already added in the collection.
Becouse of the object reuse it finds this PK object and returns. In jboss 3.2.3 this was not the case.
A posible fix from my code that I found is to create new instance of the primary key class for each call of the finder method.