You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Tino Schöllhorn <t....@tiscali.de> on 2004/07/07 16:57:50 UTC
Weird behaviour of PersistenceBroker.store(Object)
Hi,
several days ago I changed from RC6 to OJB 1.0.0 and so far it is
running fine. But now I encounter a strange bug - something which has
not happened with RC6.
I have a class Team and there is a N-M-Relation between Teams and Subteam.
Now I am adding some (already persistent) Teams t1...tn to another Team t:
Team t = ......
t.addSubTeam(t1);
t.addSubTeam(t2);
PersistenceBroker pb = ....
pb.beginTransaction();
p.store(t);
p.commitTransaction();
Before the update OJB inserted all necessary rows in the database. But
now there only the *last* added Team persistent. The other thing is,
that t1 is not in the cache either.
But when I try to store Team t after each add-Statement the database and
the object is correctly updated!
So is this a bug or am I missing something? I suspect it is an error of
OJB ??
Glad for any help.
Tino
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Weird behaviour of PersistenceBroker.store(Object)
Posted by Tino Schöllhorn <t....@tiscali.de>.
Hello Armin,
I have to admit that I simplified the description. I am sorry for that.
I try now to give more information about my specific use-case. I have
the following classes:
class Team {
protected int id;
protected List subTeamTeams;
public void addTeam(Team t) {
TeamTeam tt = new TeamTeam();
tt.parent = this;
tt.child = t;
subTeamTeams.add(t);
}
}
class TeamTeam {
protected Team parent;
protected Team child;
protecte int position; // the reason for the association-class
}
The attachted xml-snippet contains the class-descriptors for these
classes. I also wrote a test-case:
PersistenceBroker pb = DataObjectHelper.getPBFromAlias("kos_db");
Team t = Team.getTeamById(pb, 36);
logger.info("Team t: " + t);
Team t1 = Team.getTeamById(pb, 13);
logger.info("t1: " + t1);
t.addSubTeam(t1);
//
// if the following line is active everything works fine. but if
// the I store the Object t just once after adding all other Teams
// only the last one is made persistent
//t.store();
Team t2 = Team.getTeamById(pb, 7);
logger.info("t2: " + t2);
t.addSubTeam(t2);
t.store();
The other thing is: I also could reproduce this behaviour with relations
where no association-class is involved. So the error can't be there.
If you need more information please let me know. For now I have a
workaround - but if this is an OJB-bug it should be solved.
Regards
Tino
Armin Waibel wrote:
> Hi Tino,
>
> I wrote a quick test and can't reproduce the problem you described.
> The test do exactly what you described:
> - Movie m:n Actor
> - create an Movie object with dependent Actor objects
> - add already existing Actor's to the existing Movie object
>
> movie.getActors().add(a_1);
> movie.getActors().add(a_2);
> broker.beginTransaction();
> broker.store(movie);
> broker.commitTransaction();
>
> This test pass (see ...broker.M2NTest#testAddNewEntriesTTTF in CVS)
>
> This shouldn't be the problem, but do you avoid a RemovalAware
> Collection class in collection-descriptor?
> e.g. by setting
> collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
>
> http://db.apache.org/ojb/docu/guides/basic-technique.html#Support+for+Non-Decomposed+m%3An+Mappings
>
>
> Please post more info (metadata mapping)
>
> regards,
> Armin
>
> Tino Schöllhorn wrote:
>
>> Hi,
>>
>> several days ago I changed from RC6 to OJB 1.0.0 and so far it is
>> running fine. But now I encounter a strange bug - something which has
>> not happened with RC6.
>>
>> I have a class Team and there is a N-M-Relation between Teams and
>> Subteam.
>>
>> Now I am adding some (already persistent) Teams t1...tn to another
>> Team t:
>>
>> Team t = ......
>> t.addSubTeam(t1);
>> t.addSubTeam(t2);
>>
>> PersistenceBroker pb = ....
>> pb.beginTransaction();
>> p.store(t);
>> p.commitTransaction();
>>
>> Before the update OJB inserted all necessary rows in the database. But
>> now there only the *last* added Team persistent. The other thing is,
>> that t1 is not in the cache either.
>>
>> But when I try to store Team t after each add-Statement the database
>> and the object is correctly updated!
>>
>> So is this a bug or am I missing something? I suspect it is an error
>> of OJB ??
>>
>> Glad for any help.
>> Tino
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
Re: Weird behaviour of PersistenceBroker.store(Object)
Posted by Armin Waibel <ar...@apache.org>.
Hi Tino,
I wrote a quick test and can't reproduce the problem you described.
The test do exactly what you described:
- Movie m:n Actor
- create an Movie object with dependent Actor objects
- add already existing Actor's to the existing Movie object
movie.getActors().add(a_1);
movie.getActors().add(a_2);
broker.beginTransaction();
broker.store(movie);
broker.commitTransaction();
This test pass (see ...broker.M2NTest#testAddNewEntriesTTTF in CVS)
This shouldn't be the problem, but do you avoid a RemovalAware
Collection class in collection-descriptor?
e.g. by setting
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
http://db.apache.org/ojb/docu/guides/basic-technique.html#Support+for+Non-Decomposed+m%3An+Mappings
Please post more info (metadata mapping)
regards,
Armin
Tino Schöllhorn wrote:
> Hi,
>
> several days ago I changed from RC6 to OJB 1.0.0 and so far it is
> running fine. But now I encounter a strange bug - something which has
> not happened with RC6.
>
> I have a class Team and there is a N-M-Relation between Teams and Subteam.
>
> Now I am adding some (already persistent) Teams t1...tn to another Team t:
>
> Team t = ......
> t.addSubTeam(t1);
> t.addSubTeam(t2);
>
> PersistenceBroker pb = ....
> pb.beginTransaction();
> p.store(t);
> p.commitTransaction();
>
> Before the update OJB inserted all necessary rows in the database. But
> now there only the *last* added Team persistent. The other thing is,
> that t1 is not in the cache either.
>
> But when I try to store Team t after each add-Statement the database and
> the object is correctly updated!
>
> So is this a bug or am I missing something? I suspect it is an error of
> OJB ??
>
> Glad for any help.
> Tino
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org