Scott and Craig thanks for taking a stab at this, unfortunately, in my
previous post, the snippet I posted wasn't correct (I stripped out my debug
stuff and removed a line I shouldn't have), here's the proper code,
including my debug messages:
Expression teamqual = ExpressionFactory.matchExp("teamname",
teamname);
SelectQuery teamsquery = new SelectQuery(Teams.class, teamqual);
List teams = ctxt.performQuery(teamsquery);
Expression userqual = ExpressionFactory.matchExp("username",
username);
SelectQuery usersquery = new SelectQuery(Users.class, userqual);
List users = ctxt.performQuery(usersquery);
Teams myteam = (Teams)teams.get(0);
Users myuser = (Users)users.get(0);
List myteamlist = myteam.getTeamsTOusers();
System.out.println("before adding size");
System.out.println(myteamlist.size());
if(!myteamlist.contains(myuser)){
myteam.addToTeamsTOusers(myuser);
ctxt.commitChanges(Level.INFO);
}
myteamlist = myteam.getTeamsTOusers();
System.out.println("after adding user");
System.out.println(myteamlist.size());
Iterator iter2 = myteamlist.iterator();
while(iter2.hasNext()){
Users iteruser = (Users)iter2.next();
System.out.println(iteruser.getUsername());
}
And here's the console output from Tomcat, with some comments from me:
before adding size
0 <--Here's myteam.getTeamsTOusers().size() before we
create the association
after adding user <--We've added the user and called
ctxt.commitChanges(Level.INFO); but no INSERTs are generated
1 <--myteam.getTeamsTOusers().size() again, the n:m
association exists ONLY in the object model
testuser <--and here's .getUsername() pointing toward the
correct user
So I know the myteam.addToTeamsTOusers(myuser); method is working, but for
some reason, Cayenne only creates the association in the object model and
doesn't persist the changes to disk. There are no INSERT statements
getting generated.
Below is my datamap. Sorry to clutter everyone's inboxes with this, I'd
really appreciate any help I could get. I really like Cayenne, but I can't
seem to get this issue sorted out.
<?xml version="1.0" encoding="UTF-8"?>
<data-map project-version="1.0">
<db-entity name="teams">
<db-attribute name="teamdesc" type="CHAR" length="255"/>
<db-attribute name="teamid" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="10"/>
<db-attribute name="teamname" type="CHAR" isMandatory="true" length="50"/>
</db-entity>
<db-entity name="users">
<db-attribute name="pass" type="CHAR" isMandatory="true" length="20"/>
<db-attribute name="userid" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="10"/>
<db-attribute name="username" type="CHAR" isMandatory="true" length="50"/>
</db-entity>
<db-entity name="userteam">
<db-attribute name="teams_teamid" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="10"/>
<db-attribute name="users_userid" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="10"/>
</db-entity>
<obj-entity name="Teams" className="com.db.Teams" dbEntityName="teams">
<obj-attribute name="teamdesc" type="java.lang.String"
db-attribute-path="teamdesc"/>
<obj-attribute name="teamname" type="java.lang.String"
db-attribute-path="teamname"/>
</obj-entity>
<obj-entity name="Users" className="com.db.Users" dbEntityName="users">
<obj-attribute name="pass" type="java.lang.String"
db-attribute-path="pass"/>
<obj-attribute name="username" type="java.lang.String"
db-attribute-path="username"/>
</obj-entity>
<db-relationship name="teamsTOuserteam" source="teams" target="userteam"
toDependentPK="true" toMany="true">
<db-attribute-pair source="teamid" target="teams_teamid"/>
</db-relationship>
<db-relationship name="usersTOuserteam" source="users" target="userteam"
toDependentPK="true" toMany="true">
<db-attribute-pair source="userid" target="users_userid"/>
</db-relationship>
<db-relationship name="userteamTOteams" source="userteam" target="teams"
toDependentPK="false" toMany="false">
<db-attribute-pair source="teams_teamid" target="teamid"/>
</db-relationship>
<db-relationship name="userteamTOusers" source="userteam" target="users"
toDependentPK="false" toMany="false">
<db-attribute-pair source="users_userid" target="userid"/>
</db-relationship>
<obj-relationship name="teamsTOusers" source="Teams" target="Users"
toMany="true">
<db-relationship-ref source="teams" target="userteam"
name="teamsTOuserteam"/>
<db-relationship-ref source="userteam" target="users"
name="userteamTOusers"/>
</obj-relationship>
<obj-relationship name="usersTOteams" source="Users" target="Teams"
toMany="true">
<db-relationship-ref source="users" target="userteam"
name="usersTOuserteam"/>
<db-relationship-ref source="userteam" target="teams"
name="userteamTOteams"/>
</obj-relationship>
</data-map>
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
This archive was generated by hypermail 2.0.0 : Tue Jun 24 2003 - 12:27:48 EDT