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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




<!-- Team-->
<class-descriptor class="kos.intranet2.om.Team" table="Team">
        <field-descriptor name="id" column="TE_ID" jdbc-type="INTEGER" 
        primarykey="true" autoincrement="true" access="readonly"/>
                                                        
     <collection-descriptor
        name="subTeamLinks"
        element-class-ref="kos.intranet2.om.TeamTeam"
        auto-retrieve="true"
        auto-update="object"
        auto-delete="object"
        orderby="position">
        
        <inverse-foreignkey field-ref="parentId"/>
        <attribute attribute-name="reverseReference" attribute-value="parent"/>
     </collection-descriptor>
</class-descriptor>
<!-- Team End -->

<!-- TeamTeam -->
<class-descriptor class="kos.intranet2.om.TeamTeam" table="Team_Team">
        <field-descriptor name="id" column="TETE_ID" jdbc-type="INTEGER" 
        primarykey="true" autoincrement="true" access="readonly"/>
        
        <field-descriptor name="position" column="TETE_Position" jdbc-type="INTEGER"/>
        <field-descriptor name="parentId" column="TETE_Master" jdbc-type="INTEGER" 
access="anonymous"/>
        <field-descriptor name="childId" column="TETE_Detail" jdbc-type="INTEGER" 
access="anonymous"/>
        <field-descriptor name="creationDate" column="TETE_CreationDate" 
jdbc-type="TIMESTAMP"/>

        <reference-descriptor name="parent" class-ref="kos.intranet2.om.Team">
                <foreignkey field-ref="parentId"/>
                <attribute attribute-name="reverseCollection" 
attribute-value="subTeamLinks"/>
        </reference-descriptor>
        
        <reference-descriptor name="child"              
class-ref="kos.intranet2.om.Team">
                <foreignkey field-ref="childId"/>
                <attribute attribute-name="reverseCollection" 
attribute-value="parentTeamLinks"/>
        </reference-descriptor>
</class-descriptor>
<!-- TeamTeam End-->
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to