You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by marco turchi <ma...@gmail.com> on 2006/12/08 16:53:00 UTC

many to many relation

Hi,
I'm a new Cayenne user and I'm trying to create a many to many relationship.
This is the whole situation:
Entity<<->>NameRelation<<->>Name

NameRelation has a composed key id_entity, id_name

I create the model where
Entity has a "to many" relationship to Name, and a relationship that
forwards its key to NameRelation (the flag "To Dep PK" enabled)

Name has  a relationship that forwards its key to NameRelation (the flag "To
Dep PK" enabled)

NameRelation has two "to many" relationship directed to Name and Entity.

The problem is that when I insert an element into Entity and into Name, the
software did not insert automatically the row into NameRelation.

maybe it is an easy question for you, but not for me... :-(
please, can you help me?

Thanks a lot
Marco

Re: many to many relation

Posted by marco turchi <ma...@gmail.com>.
now it works...
thanks a lot

Marco


On 12/11/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
>
> On Dec 11, 2006, at 17:36, marco turchi wrote:
>
> > the problem is that using the moduler I'm not able to create an
> > obj-relationship without create a new db-relationship. It means that I
> > obtain more relationships than the relationships you shown me in
> > the example
> > (I obtain what I wrote in the previous email).
>
> Okay, I now see the problem. In the "ObjRelationship Inspector"
> dialog, do not press any of the buttons to create a new db
> relationship. I just clicked once inside the DbRelationships-table of
> the dialog and a dropdown show up. Select the db-relationship and
> erverything should be ok.
>
> This was how I fixed the model using the modeler.
>
> - Tore.
>
>

Re: many to many relation

Posted by Tore Halset <ha...@pvv.ntnu.no>.
On Dec 11, 2006, at 17:36, marco turchi wrote:

> the problem is that using the moduler I'm not able to create an
> obj-relationship without create a new db-relationship. It means that I
> obtain more relationships than the relationships you shown me in  
> the example
> (I obtain what I wrote in the previous email).

Okay, I now see the problem. In the "ObjRelationship Inspector"  
dialog, do not press any of the buttons to create a new db  
relationship. I just clicked once inside the DbRelationships-table of  
the dialog and a dropdown show up. Select the db-relationship and  
erverything should be ok.

This was how I fixed the model using the modeler.

  - Tore.


Re: many to many relation

Posted by Robert Zeigler <ro...@roxanemy.com>.
Yes, you should use the cayenne "removeFrom"/"addTo" methods.  These methods help ensure that bi-directional relationships stay consistent for you.  Otherwise, you have to manage that by hand.

Robert

On Sep 30, 2010, at 9/301:19 PM , gilbertoca wrote:

> 
> 
> gilbertoca wrote:
>> 
>> Yes, but for some reason it leaves the database in a inconsistent state:
>> 
>> 
>>> Testcase:
>>> com.google.constructor.extras.security.shiro.cayenne.UserCayenneTest:       
>>> Caused an ERROR
>>> Referential integrity constraint violation: "FK_SHIRO_USER_ROLE_ROLE_ID:
>>> PUBLIC.SHIRO_USER_ROLE FOREIGN KEY(ROLE_ID) REFERENCES
>>> PUBLIC.SHIRO_ROLE(ID)"; SQL statement:
>>> delete from SHIRO_ROLE where ID = ? [23003-131]
>>> org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation:
>>> "FK_SHIRO_USER_ROLE_ROLE_ID: PUBLIC.SHIRO_USER_ROLE FOREIGN KEY(ROLE_ID)
>>> REFERENCES PUBLIC.SHIRO_ROLE(ID)"; SQL statement:
>>> delete from SHIRO_ROLE where ID = ? [23003-131]
>>>        at
>>> org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
>>> 
>> I will try to find the problem!
>> 
>> 
> I've found the problem. I was using:
> userUpdated.getRoles().remove(roleADMIN);
> 
> instead of
> 
> userUpdated.removeFromRoles(roleADMIN); 
> 
> So, can't I use those LIST methods with Cayenne? Just the Cayenne one!
> 
> Thanks a lot, Robert.
> 
> Regards,
> 
> Gilberto
> 
> -- 
> View this message in context: http://cayenne.195.n3.nabble.com/many-to-many-relation-tp3491p1609999.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: many to many relation

Posted by gilbertoca <gi...@gmail.com>.

gilbertoca wrote:
> 
> Yes, but for some reason it leaves the database in a inconsistent state:
> 
> 
>> Testcase:
>> com.google.constructor.extras.security.shiro.cayenne.UserCayenneTest:       
>> Caused an ERROR
>> Referential integrity constraint violation: "FK_SHIRO_USER_ROLE_ROLE_ID:
>> PUBLIC.SHIRO_USER_ROLE FOREIGN KEY(ROLE_ID) REFERENCES
>> PUBLIC.SHIRO_ROLE(ID)"; SQL statement:
>> delete from SHIRO_ROLE where ID = ? [23003-131]
>> org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation:
>> "FK_SHIRO_USER_ROLE_ROLE_ID: PUBLIC.SHIRO_USER_ROLE FOREIGN KEY(ROLE_ID)
>> REFERENCES PUBLIC.SHIRO_ROLE(ID)"; SQL statement:
>> delete from SHIRO_ROLE where ID = ? [23003-131]
>>         at
>> org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
>> 
> I will try to find the problem!
> 
> 
I've found the problem. I was using:
userUpdated.getRoles().remove(roleADMIN);

instead of

userUpdated.removeFromRoles(roleADMIN); 

So, can't I use those LIST methods with Cayenne? Just the Cayenne one!

Thanks a lot, Robert.

Regards,

Gilberto

-- 
View this message in context: http://cayenne.195.n3.nabble.com/many-to-many-relation-tp3491p1609999.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: many to many relation

Posted by gilbertoca <gi...@gmail.com>.

Robert Zeigler-6 wrote:
> 
> Don't use cascade from User -> Role or from Role -> User.  Given that a
> user can existing with 0 or more roles, and a role can exist with 0 or
> more users... cascade definitely not what you want there.  You might
> believe that "cascade" is the right choice because you want to "cascade"
> the deletion from User to the association table.  But note that the delete
> rule is on the object relationship: from user -> role (and vice versa). 
> 
Something that would help a lot is just one place to define relationship. It
seems that object relationship and db relationship are things different and
that confuses me!


Robert Zeigler-6 wrote:
> 
>  If you had  modeled the join table as an object entity, /then/ you would
> make the delete rule (from user to association table) cascade, and the
> delete rule form association table -> role "nullify".  But since you're
> working with a "flattened" relationship, you just specify Nullify, and
> cayenne will do the right thing.  
> 
Yes, taking your advice it seems to work. But ...


Robert Zeigler-6 wrote:
> 
> To prove this, I changed the delete rule from user -> role to Nullify, and
> from role -> user to Nullify, then added the following lines to the
> "testAddAndRemoveUser" test:
> 
>         lU = (List<User>) userService.getAll();
>         System.out.println("***** Checking # users *****");
>         assertEquals(3, lU.size());
>         System.out.println("***** Checking # roles *****");
>         assertEquals(2, roleService.getAll().size());
> 
> 

Yes, but for some reason it leaves the database in a inconsistent state:


> Testcase:
> com.google.constructor.extras.security.shiro.cayenne.UserCayenneTest:       
> Caused an ERROR
> Referential integrity constraint violation: "FK_SHIRO_USER_ROLE_ROLE_ID:
> PUBLIC.SHIRO_USER_ROLE FOREIGN KEY(ROLE_ID) REFERENCES
> PUBLIC.SHIRO_ROLE(ID)"; SQL statement:
> delete from SHIRO_ROLE where ID = ? [23003-131]
> org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation:
> "FK_SHIRO_USER_ROLE_ROLE_ID: PUBLIC.SHIRO_USER_ROLE FOREIGN KEY(ROLE_ID)
> REFERENCES PUBLIC.SHIRO_ROLE(ID)"; SQL statement:
> delete from SHIRO_ROLE where ID = ? [23003-131]
>         at
> org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
> 
I will try to find the problem!



Robert Zeigler-6 wrote:
> 
> Without the change, you get 0 users and 0 roles.  Because:
> deleteUser -> deleting the user, who is associated with the default role;
> b/c of cascade rule, default role is deleted.  Default role is associated
> with all users; because of cascade rule, all users are deleted.  Because
> of cascade rule, any additional roles (admin) associated with users are
> /also/ deleted.  So the net result is: you have no users or roles left in
> your db at the end of your test. :) 
> 
That was the situation! :)

Thanks a lot, Robert.

Regards,

Gilberto


-- 
View this message in context: http://cayenne.195.n3.nabble.com/many-to-many-relation-tp3491p1609838.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: many to many relation

Posted by Robert Zeigler <ro...@roxanemy.com>.
Don't use cascade from User -> Role or from Role -> User.  Given that a user can existing with 0 or more roles, and a role can exist with 0 or more users... cascade definitely not what you want there.  You might believe that "cascade" is the right choice because you want to "cascade" the deletion from User to the association table.  But note that the delete rule is on the object relationship: from user -> role (and vice versa).  If you had  modeled the join table as an object entity, /then/ you would make the delete rule (from user to association table) cascade, and the delete rule form association table -> role "nullify".  But since you're working with a "flattened" relationship, you just specify Nullify, and cayenne will do the right thing.  To prove this, I changed the delete rule from user -> role to Nullify, and from role -> user to Nullify, then added the following lines to the "testAddAndRemoveUser" test:

        lU = (List<User>) userService.getAll();
        System.out.println("***** Checking # users *****");
        assertEquals(3, lU.size());
        System.out.println("***** Checking # roles *****");
        assertEquals(2, roleService.getAll().size());

Without the change, you get 0 users and 0 roles.  Because:
deleteUser -> deleting the user, who is associated with the default role; b/c of cascade rule, default role is deleted.  Default role is associated with all users; because of cascade rule, all users are deleted.  Because of cascade rule, any additional roles (admin) associated with users are /also/ deleted.  So the net result is: you have no users or roles left in your db at the end of your test. :) 

With the change, you get 3 users and 2 roles.

Cheers,

Robert


On Sep 29, 2010, at 9/291:07 PM , gilbertoca wrote:

> 
> Some progress ... rs rs rs
> Clicking just one time on ObjRelationshipInspector[1] and confirming the new
> db relationship path my test works but not correctly. In DELETE RULES I've
> put CASCADE.
> So, just remembering:
> 
> User <--> Role
> 
> tables: 
> SHIRO_USER --> SHIRO_USER_ROLE<---SHIRO_ROLE
> SHIRO_ROLE-->SHIRO_ROLE_PERMISSION
> 
> The Cayenne config files:
> http://code.google.com/p/construtor/source/browse/#svn/trunk/click-orm-integration/orm/src/test/resources
> The test case:
> http://code.google.com/p/construtor/source/browse/trunk/click-orm-integration/orm/src/test/java/com/google/construtor/extras/security/shiro/cayenne/UserCayenneTest.java
> 
> When doing userService.delete(user.getId());, cayenne removes everything(in
> this order):
> SHIRO_USER --> SHIRO_USER_ROLE<---SHIRO_ROLE-->SHIRO_ROLE_PERMISSION
> 
> But should be this way:
> SHIRO_USER --> SHIRO_USER_ROLE
> 
> 
> 
>> ===========testAddAndRemoveUser======
>> 2010-09-29 14:32:41,547 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,547 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,548 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT t0.ID, t0.DESCRIPTION, t0.NAME FROM SHIRO_ROLE t0 WHERE t0.NAME = ?
>> [bind: 1->NAME:'USER_ROLE'] 
>> 2010-09-29 14:32:41,550 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 1 row. - took 1 ms. 
>> 2010-09-29 14:32:41,550 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> ***** getting role {<ObjectId:Role, ID=-2>; committed; [id=>-2; users=>?;
>> description=>Default role for all Users; name=>USER_ROLE; permissions=>?]}
>> for a new user. *****
>> 2010-09-29 14:32:41,615 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 2 queries. 
>> 2010-09-29 14:32:41,616 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,837 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = 'SHIRO_USER' 
>> 2010-09-29 14:32:41,844 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 1 row. - took 7 ms. 
>> 2010-09-29 14:32:41,845 INFO [org.apache.cayenne.access.QueryLogger] -
>> UPDATE AUTO_PK_SUPPORT SET NEXT_ID = NEXT_ID + 20 WHERE TABLE_NAME =
>> 'SHIRO_USER' 
>> 2010-09-29 14:32:41,847 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,848 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 2 queries. 
>> 2010-09-29 14:32:41,849 INFO [org.apache.cayenne.access.QueryLogger] -
>> INSERT INTO SHIRO_USER (EMAIL, ID, PASSWORD, USERNAME, VERSION) VALUES (?,
>> ?, ?, ?, ?) 
>> 2010-09-29 14:32:41,850 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->EMAIL:'testuser@appfuse.org', 2->ID:1200,
>> 3->PASSWORD:'testpass', 4->USERNAME:'Test', 5->VERSION:NULL] 
>> 2010-09-29 14:32:41,851 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,851 INFO [org.apache.cayenne.access.QueryLogger] -
>> INSERT INTO SHIRO_USER_ROLE (ROLE_ID, USER_ID) VALUES (?, ?) 
>> 2010-09-29 14:32:41,851 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ROLE_ID:-2, 2->USER_ID:1200] 
>> 2010-09-29 14:32:41,852 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,855 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> 2010-09-29 14:32:41,855 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,855 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,856 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
>> SHIRO_USER t0 
>> 2010-09-29 14:32:41,857 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 4 rows. - took 1 ms. 
>> 2010-09-29 14:32:41,857 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> ***** Does the object was update or shoul I get it by find method? *****
>> ***** should use cache? {<ObjectId:User, ID=1200>; committed; [id=>1200;
>> username=>Test; email=>testuser@appfuse.org; roles=>(..);
>> password=>testpass; version=>null]}*****
>> 2010-09-29 14:32:41,861 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,862 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,871 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT t0.ROLE_ID, t0.PERMISSION FROM SHIRO_ROLE_PERMISSION t0 WHERE
>> t0.ROLE_ID = ? [bind: 1->ROLE_ID:-2] - prepared in 9 ms. 
>> 2010-09-29 14:32:41,872 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 1 row. - took 10 ms. 
>> 2010-09-29 14:32:41,873 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> 2010-09-29 14:32:41,876 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,876 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,883 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT DISTINCT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
>> SHIRO_USER t0 JOIN SHIRO_USER_ROLE t1 ON (t0.ID = t1.USER_ID) WHERE
>> t1.ROLE_ID = ? [bind: 1->ROLE_ID:-2] - prepared in 6 ms. 
>> 2010-09-29 14:32:41,884 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 4 rows. - took 7 ms. 
>> 2010-09-29 14:32:41,890 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> 2010-09-29 14:32:41,891 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,891 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,891 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT DISTINCT t0.ID, t0.DESCRIPTION, t0.NAME FROM SHIRO_ROLE t0 JOIN
>> SHIRO_USER_ROLE t1 ON (t0.ID = t1.ROLE_ID) WHERE t1.USER_ID = ? [bind:
>> 1->USER_ID:-3] 
>> 2010-09-29 14:32:41,892 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 1 row. - took 1 ms. 
>> 2010-09-29 14:32:41,892 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> 2010-09-29 14:32:41,893 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,893 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,893 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT DISTINCT t0.ID, t0.DESCRIPTION, t0.NAME FROM SHIRO_ROLE t0 JOIN
>> SHIRO_USER_ROLE t1 ON (t0.ID = t1.ROLE_ID) WHERE t1.USER_ID = ? [bind:
>> 1->USER_ID:-2] 
>> 2010-09-29 14:32:41,894 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 1 row. - took 1 ms. 
>> 2010-09-29 14:32:41,894 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> 2010-09-29 14:32:41,895 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,895 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,895 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT t0.ROLE_ID, t0.PERMISSION FROM SHIRO_ROLE_PERMISSION t0 WHERE
>> t0.ROLE_ID = ? [bind: 1->ROLE_ID:-1] 
>> 2010-09-29 14:32:41,896 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 2 rows. - took 1 ms. 
>> 2010-09-29 14:32:41,896 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> 2010-09-29 14:32:41,897 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,897 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,898 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT DISTINCT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
>> SHIRO_USER t0 JOIN SHIRO_USER_ROLE t1 ON (t0.ID = t1.USER_ID) WHERE
>> t1.ROLE_ID = ? [bind: 1->ROLE_ID:-1] 
>> 2010-09-29 14:32:41,898 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 1 row. - took 1 ms. 
>> 2010-09-29 14:32:41,898 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> 2010-09-29 14:32:41,901 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 4 queries. 
>> 2010-09-29 14:32:41,902 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,902 INFO [org.apache.cayenne.access.QueryLogger] -
>> DELETE FROM SHIRO_USER_ROLE WHERE ROLE_ID = ? AND USER_ID = ? 
>> 2010-09-29 14:32:41,903 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ROLE_ID:-2, 2->USER_ID:-1] 
>> 2010-09-29 14:32:41,903 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,903 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ROLE_ID:-1, 2->USER_ID:-1] 
>> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ROLE_ID:-2, 2->USER_ID:-3] 
>> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ROLE_ID:-2, 2->USER_ID:-2] 
>> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ROLE_ID:-2, 2->USER_ID:1200] 
>> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] -
>> DELETE FROM SHIRO_ROLE_PERMISSION WHERE PERMISSION = ? AND ROLE_ID = ? 
>> 2010-09-29 14:32:41,906 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->PERMISSION:'secure', 2->ROLE_ID:-1] 
>> 2010-09-29 14:32:41,906 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,906 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->PERMISSION:'none', 2->ROLE_ID:-2] 
>> 2010-09-29 14:32:41,907 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,907 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->PERMISSION:'admin', 2->ROLE_ID:-1] 
>> 2010-09-29 14:32:41,907 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,908 INFO [org.apache.cayenne.access.QueryLogger] -
>> DELETE FROM SHIRO_USER WHERE ID = ? 
>> 2010-09-29 14:32:41,908 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ID:1200] 
>> 2010-09-29 14:32:41,909 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,909 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ID:-1] 
>> 2010-09-29 14:32:41,909 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,910 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ID:-3] 
>> 2010-09-29 14:32:41,910 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,910 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ID:-2] 
>> 2010-09-29 14:32:41,911 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,911 INFO [org.apache.cayenne.access.QueryLogger] -
>> DELETE FROM SHIRO_ROLE WHERE ID = ? 
>> 2010-09-29 14:32:41,911 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ID:-1] 
>> 2010-09-29 14:32:41,912 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,912 INFO [org.apache.cayenne.access.QueryLogger] -
>> [bind: 1->ID:-2] 
>> 2010-09-29 14:32:41,913 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> updated 1 row. 
>> 2010-09-29 14:32:41,914 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> ***** what does happen if the entity doesn't exist? *****
>> 2010-09-29 14:32:41,915 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,915 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,916 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
>> SHIRO_USER t0 WHERE t0.ID = ? [bind: 1->ID:1200] 
>> 2010-09-29 14:32:41,916 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 0 rows. - took 1 ms. 
>> 2010-09-29 14:32:41,917 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> ===========testAddUserRole======
>> 2010-09-29 14:32:41,918 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> will run 1 query. 
>> 2010-09-29 14:32:41,919 INFO [org.apache.cayenne.access.QueryLogger] - ---
>> transaction started. 
>> 2010-09-29 14:32:41,919 INFO [org.apache.cayenne.access.QueryLogger] -
>> SELECT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
>> SHIRO_USER t0 WHERE t0.ID = ? [bind: 1->ID:-2] 
>> 2010-09-29 14:32:41,920 INFO [org.apache.cayenne.access.QueryLogger] - ===
>> returned 0 rows. - took 1 ms. 
>> 2010-09-29 14:32:41,920 INFO [org.apache.cayenne.access.QueryLogger] - +++
>> transaction committed. 
>> Tests run: 7, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.584 sec
>> <<< FAILURE!
>> 
>> Results :
>> 
>> Tests in error: 
>> 
>> testAddUserRole(com.google.constructor.extras.security.shiro.cayenne.UserCayenneTest)
>> 
>> 
> 
> Is there anything wrong with my configuration?
> You can try it just checking out the project[2] (Apache License 2.0): 
> svn checkout
> http://construtor.googlecode.com/svn/trunk/click-orm-integration coi
> cd coi/orm
> mvn sql:execute ---> will create a H2 database in the data folder
> mvn clean test -Dtest=UserCayenneTest
> 
> It is a multi-module maven project:
> 
> # orm/ =======> JPA and Cayenne implementation of IService
>                         =======> ShiroJPARealm a little implementation of
> Shiro framework (used on rolesecurity module example)
>                         =======> ShiroCayenneRealm a little implementation
> of Shiro framework (doesn't have module example, just test for now)
> # rolesecurity/ =======> rolesecurity module example showing how to setup
> Apache Shiro with click and demonstrate the ShiroJPARealm use.
> 
> Hope someone has time to take a look on it. 
> 
> 
> Regards,
> 
> Gilberto
> 
> PS: Why does cayenne not do a rollback when occurs an exception? See the the
> comment test method in the  UserCayenneTest class.
> 
> [1]http://dl.dropbox.com/u/9093640/ObjRelationshipInspector2.png
> [2]http://code.google.com/p/construtor/
> 
> -- 
> View this message in context: http://cayenne.195.n3.nabble.com/many-to-many-relation-tp3491p1603892.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: many to many relation

Posted by gilbertoca <gi...@gmail.com>.
Some progress ... rs rs rs
Clicking just one time on ObjRelationshipInspector[1] and confirming the new
db relationship path my test works but not correctly. In DELETE RULES I've
put CASCADE.
So, just remembering:

User <--> Role

tables: 
SHIRO_USER --> SHIRO_USER_ROLE<---SHIRO_ROLE
SHIRO_ROLE-->SHIRO_ROLE_PERMISSION

The Cayenne config files:
http://code.google.com/p/construtor/source/browse/#svn/trunk/click-orm-integration/orm/src/test/resources
The test case:
http://code.google.com/p/construtor/source/browse/trunk/click-orm-integration/orm/src/test/java/com/google/construtor/extras/security/shiro/cayenne/UserCayenneTest.java

When doing userService.delete(user.getId());, cayenne removes everything(in
this order):
SHIRO_USER --> SHIRO_USER_ROLE<---SHIRO_ROLE-->SHIRO_ROLE_PERMISSION

But should be this way:
SHIRO_USER --> SHIRO_USER_ROLE



> ===========testAddAndRemoveUser======
> 2010-09-29 14:32:41,547 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,547 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,548 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT t0.ID, t0.DESCRIPTION, t0.NAME FROM SHIRO_ROLE t0 WHERE t0.NAME = ?
> [bind: 1->NAME:'USER_ROLE'] 
> 2010-09-29 14:32:41,550 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 1 row. - took 1 ms. 
> 2010-09-29 14:32:41,550 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> ***** getting role {<ObjectId:Role, ID=-2>; committed; [id=>-2; users=>?;
> description=>Default role for all Users; name=>USER_ROLE; permissions=>?]}
> for a new user. *****
> 2010-09-29 14:32:41,615 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 2 queries. 
> 2010-09-29 14:32:41,616 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,837 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = 'SHIRO_USER' 
> 2010-09-29 14:32:41,844 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 1 row. - took 7 ms. 
> 2010-09-29 14:32:41,845 INFO [org.apache.cayenne.access.QueryLogger] -
> UPDATE AUTO_PK_SUPPORT SET NEXT_ID = NEXT_ID + 20 WHERE TABLE_NAME =
> 'SHIRO_USER' 
> 2010-09-29 14:32:41,847 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,848 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 2 queries. 
> 2010-09-29 14:32:41,849 INFO [org.apache.cayenne.access.QueryLogger] -
> INSERT INTO SHIRO_USER (EMAIL, ID, PASSWORD, USERNAME, VERSION) VALUES (?,
> ?, ?, ?, ?) 
> 2010-09-29 14:32:41,850 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->EMAIL:'testuser@appfuse.org', 2->ID:1200,
> 3->PASSWORD:'testpass', 4->USERNAME:'Test', 5->VERSION:NULL] 
> 2010-09-29 14:32:41,851 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,851 INFO [org.apache.cayenne.access.QueryLogger] -
> INSERT INTO SHIRO_USER_ROLE (ROLE_ID, USER_ID) VALUES (?, ?) 
> 2010-09-29 14:32:41,851 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ROLE_ID:-2, 2->USER_ID:1200] 
> 2010-09-29 14:32:41,852 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,855 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> 2010-09-29 14:32:41,855 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,855 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,856 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
> SHIRO_USER t0 
> 2010-09-29 14:32:41,857 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 4 rows. - took 1 ms. 
> 2010-09-29 14:32:41,857 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> ***** Does the object was update or shoul I get it by find method? *****
> ***** should use cache? {<ObjectId:User, ID=1200>; committed; [id=>1200;
> username=>Test; email=>testuser@appfuse.org; roles=>(..);
> password=>testpass; version=>null]}*****
> 2010-09-29 14:32:41,861 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,862 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,871 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT t0.ROLE_ID, t0.PERMISSION FROM SHIRO_ROLE_PERMISSION t0 WHERE
> t0.ROLE_ID = ? [bind: 1->ROLE_ID:-2] - prepared in 9 ms. 
> 2010-09-29 14:32:41,872 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 1 row. - took 10 ms. 
> 2010-09-29 14:32:41,873 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> 2010-09-29 14:32:41,876 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,876 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,883 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT DISTINCT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
> SHIRO_USER t0 JOIN SHIRO_USER_ROLE t1 ON (t0.ID = t1.USER_ID) WHERE
> t1.ROLE_ID = ? [bind: 1->ROLE_ID:-2] - prepared in 6 ms. 
> 2010-09-29 14:32:41,884 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 4 rows. - took 7 ms. 
> 2010-09-29 14:32:41,890 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> 2010-09-29 14:32:41,891 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,891 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,891 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT DISTINCT t0.ID, t0.DESCRIPTION, t0.NAME FROM SHIRO_ROLE t0 JOIN
> SHIRO_USER_ROLE t1 ON (t0.ID = t1.ROLE_ID) WHERE t1.USER_ID = ? [bind:
> 1->USER_ID:-3] 
> 2010-09-29 14:32:41,892 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 1 row. - took 1 ms. 
> 2010-09-29 14:32:41,892 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> 2010-09-29 14:32:41,893 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,893 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,893 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT DISTINCT t0.ID, t0.DESCRIPTION, t0.NAME FROM SHIRO_ROLE t0 JOIN
> SHIRO_USER_ROLE t1 ON (t0.ID = t1.ROLE_ID) WHERE t1.USER_ID = ? [bind:
> 1->USER_ID:-2] 
> 2010-09-29 14:32:41,894 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 1 row. - took 1 ms. 
> 2010-09-29 14:32:41,894 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> 2010-09-29 14:32:41,895 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,895 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,895 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT t0.ROLE_ID, t0.PERMISSION FROM SHIRO_ROLE_PERMISSION t0 WHERE
> t0.ROLE_ID = ? [bind: 1->ROLE_ID:-1] 
> 2010-09-29 14:32:41,896 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 2 rows. - took 1 ms. 
> 2010-09-29 14:32:41,896 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> 2010-09-29 14:32:41,897 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,897 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,898 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT DISTINCT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
> SHIRO_USER t0 JOIN SHIRO_USER_ROLE t1 ON (t0.ID = t1.USER_ID) WHERE
> t1.ROLE_ID = ? [bind: 1->ROLE_ID:-1] 
> 2010-09-29 14:32:41,898 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 1 row. - took 1 ms. 
> 2010-09-29 14:32:41,898 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> 2010-09-29 14:32:41,901 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 4 queries. 
> 2010-09-29 14:32:41,902 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,902 INFO [org.apache.cayenne.access.QueryLogger] -
> DELETE FROM SHIRO_USER_ROLE WHERE ROLE_ID = ? AND USER_ID = ? 
> 2010-09-29 14:32:41,903 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ROLE_ID:-2, 2->USER_ID:-1] 
> 2010-09-29 14:32:41,903 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,903 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ROLE_ID:-1, 2->USER_ID:-1] 
> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ROLE_ID:-2, 2->USER_ID:-3] 
> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,904 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ROLE_ID:-2, 2->USER_ID:-2] 
> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ROLE_ID:-2, 2->USER_ID:1200] 
> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,905 INFO [org.apache.cayenne.access.QueryLogger] -
> DELETE FROM SHIRO_ROLE_PERMISSION WHERE PERMISSION = ? AND ROLE_ID = ? 
> 2010-09-29 14:32:41,906 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->PERMISSION:'secure', 2->ROLE_ID:-1] 
> 2010-09-29 14:32:41,906 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,906 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->PERMISSION:'none', 2->ROLE_ID:-2] 
> 2010-09-29 14:32:41,907 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,907 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->PERMISSION:'admin', 2->ROLE_ID:-1] 
> 2010-09-29 14:32:41,907 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,908 INFO [org.apache.cayenne.access.QueryLogger] -
> DELETE FROM SHIRO_USER WHERE ID = ? 
> 2010-09-29 14:32:41,908 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ID:1200] 
> 2010-09-29 14:32:41,909 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,909 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ID:-1] 
> 2010-09-29 14:32:41,909 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,910 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ID:-3] 
> 2010-09-29 14:32:41,910 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,910 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ID:-2] 
> 2010-09-29 14:32:41,911 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,911 INFO [org.apache.cayenne.access.QueryLogger] -
> DELETE FROM SHIRO_ROLE WHERE ID = ? 
> 2010-09-29 14:32:41,911 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ID:-1] 
> 2010-09-29 14:32:41,912 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,912 INFO [org.apache.cayenne.access.QueryLogger] -
> [bind: 1->ID:-2] 
> 2010-09-29 14:32:41,913 INFO [org.apache.cayenne.access.QueryLogger] - ===
> updated 1 row. 
> 2010-09-29 14:32:41,914 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> ***** what does happen if the entity doesn't exist? *****
> 2010-09-29 14:32:41,915 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,915 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,916 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
> SHIRO_USER t0 WHERE t0.ID = ? [bind: 1->ID:1200] 
> 2010-09-29 14:32:41,916 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 0 rows. - took 1 ms. 
> 2010-09-29 14:32:41,917 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> ===========testAddUserRole======
> 2010-09-29 14:32:41,918 INFO [org.apache.cayenne.access.QueryLogger] - ---
> will run 1 query. 
> 2010-09-29 14:32:41,919 INFO [org.apache.cayenne.access.QueryLogger] - ---
> transaction started. 
> 2010-09-29 14:32:41,919 INFO [org.apache.cayenne.access.QueryLogger] -
> SELECT t0.ID, t0.USERNAME, t0.EMAIL, t0.PASSWORD, t0.VERSION FROM
> SHIRO_USER t0 WHERE t0.ID = ? [bind: 1->ID:-2] 
> 2010-09-29 14:32:41,920 INFO [org.apache.cayenne.access.QueryLogger] - ===
> returned 0 rows. - took 1 ms. 
> 2010-09-29 14:32:41,920 INFO [org.apache.cayenne.access.QueryLogger] - +++
> transaction committed. 
> Tests run: 7, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.584 sec
> <<< FAILURE!
> 
> Results :
> 
> Tests in error: 
>  
> testAddUserRole(com.google.constructor.extras.security.shiro.cayenne.UserCayenneTest)
> 
> 

Is there anything wrong with my configuration?
You can try it just checking out the project[2] (Apache License 2.0): 
svn checkout
http://construtor.googlecode.com/svn/trunk/click-orm-integration coi
cd coi/orm
mvn sql:execute ---> will create a H2 database in the data folder
mvn clean test -Dtest=UserCayenneTest

It is a multi-module maven project:

# orm/ =======> JPA and Cayenne implementation of IService
                         =======> ShiroJPARealm a little implementation of
Shiro framework (used on rolesecurity module example)
                         =======> ShiroCayenneRealm a little implementation
of Shiro framework (doesn't have module example, just test for now)
# rolesecurity/ =======> rolesecurity module example showing how to setup
Apache Shiro with click and demonstrate the ShiroJPARealm use.

Hope someone has time to take a look on it. 


Regards,

Gilberto

PS: Why does cayenne not do a rollback when occurs an exception? See the the
comment test method in the  UserCayenneTest class.

[1]http://dl.dropbox.com/u/9093640/ObjRelationshipInspector2.png
[2]http://code.google.com/p/construtor/

-- 
View this message in context: http://cayenne.195.n3.nabble.com/many-to-many-relation-tp3491p1603892.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: many to many relation

Posted by gilbertoca <gi...@gmail.com>.
What means this question [1]?

Here [2] I can't find any references about it.

Regards,

Gilberto

[1]https://dl.dropbox.com/u/9093640/ObjRelationshipInspector.png
[2]http://cayenne.apache.org/doc30/cayennemodeler-flattened-relationships.html
-- 
View this message in context: http://cayenne.195.n3.nabble.com/many-to-many-relation-tp3491p1575177.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: many to many relation

Posted by gilbertoca <gi...@gmail.com>.

marco turchi wrote:
> 
> the problem is that using the moduler I'm not able to create an
> obj-relationship without create a new db-relationship. It means that I
> obtain more relationships than the relationships you shown me in the
> example
> (I obtain what I wrote in the previous email).
> 

I'm with the same problem (confusion). Every time I try the Tore tip[1]
cayenne-modeler show me another dialog asking if I want create a new
db-relationship.

The example:

User <--> Role

The Cayenne config files:
http://code.google.com/p/construtor/source/browse/#svn/trunk/click-orm-integration/orm/src/test/resources

The test case:
http://code.google.com/p/construtor/source/browse/trunk/click-orm-integration/orm/src/test/java/org/apache/click/extras/security/shiro/cayenne/UserCayenneTest.java

Maybe my problem is the relationship names. 
Can anyone help?

Regards,

Gilberto

[1]http://cayenne.apache.org/doc12/cayennemodeler-flattened-relationships.html
-- 
View this message in context: http://cayenne.195.n3.nabble.com/many-to-many-relation-tp3491p1570367.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: many to many relation

Posted by marco turchi <ma...@gmail.com>.
Hi Tore,
thanks for your help...

the problem is that using the moduler I'm not able to create an
obj-relationship without create a new db-relationship. It means that I
obtain more relationships than the relationships you shown me in the example
(I obtain what I wrote in the previous email).

thanks
Marco



On 12/11/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
>
> Hello.
>
> On Dec 11, 2006, at 13:01 , marco turchi wrote:
>
> > I've read the documentation, I created a flattened many-to-many
> > relationship, but any record has been inserted inside the
> > connection table.
> >
> > I have the following tables and relationships:
>
> Your mapping is wrong. I have fixed it and included it at the bottom
> of this mail.
>
> Issuing the following java code (almost the same as yours):
>
>         String typeEntity = "myTypeEntity";
>         String term = "myTerm";
>
>         DataContext context = DataContext.createDataContext();
>
>         NeEntity entity = (NeEntity) context.newObject(NeEntity.class);
>         NeEntityName entityName = (NeEntityName) context.newObject
> (NeEntityName.class);
>         entity.setEntityType(typeEntity);
>         entityName.setName(term);
>         entity.addToEntityNames(entityName);
>
>         context.commitChanges();
>
> result in the following log:
> INFO  QueryLogger: +++ Connecting: SUCCESS.
> INFO  QueryLogger: Detected and installed adapter:
> org.apache.cayenne.dba.derby.DerbyAdapter
> INFO  QueryLogger: SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE
> TABLE_NAME = ? FOR UPDATE [bind: 'NE_ENTITY_NAME']
> INFO  QueryLogger: --- transaction started.
> INFO  QueryLogger: SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE
> TABLE_NAME = ? FOR UPDATE [bind: 'NE_ENTITY']
> INFO  QueryLogger: --- will run 3 queries.
> INFO  QueryLogger: INSERT INTO NE_ENTITY_NAME (id, name) VALUES (?, ?)
> INFO  QueryLogger: [bind: 200, 'myTerm']
> INFO  QueryLogger: === updated 1 row.
> INFO  QueryLogger: INSERT INTO NE_ENTITY (entityType, id) VALUES (?, ?)
> INFO  QueryLogger: [bind: 'myTypeEntity', 200]
> INFO  QueryLogger: === updated 1 row.
> INFO  QueryLogger: INSERT INTO NE_NAME_RELATION (id_entity,
> id_entity_name) VALUES (?, ?)
> INFO  QueryLogger: [bind: 200, 200]
> INFO  QueryLogger: === updated 1 row.
> INFO  QueryLogger: +++ transaction committed.
>
> - Tore.
>
> <?xml version="1.0" encoding="utf-8"?>
> <data-map project-version="2.0">
>        <property name="defaultPackage" value="marcoproblem.data"/>
>        <db-entity name="NE_ENTITY">
>                <db-attribute name="entityType" type="VARCHAR"
> length="255"/>
>                <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
>        </db-entity>
>        <db-entity name="NE_ENTITY_NAME">
>                <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
>                <db-attribute name="name" type="VARCHAR" length="150"/>
>        </db-entity>
>        <db-entity name="NE_NAME_RELATION">
>                <db-attribute name="id_entity" type="INTEGER"
> isPrimaryKey="true"
> isMandatory="true"/>
>                <db-attribute name="id_entity_name" type="INTEGER"
> isPrimaryKey="true" isMandatory="true"/>
>        </db-entity>
>        <obj-entity name="NeEntity" className="marcoproblem.data.NeEntity"
> dbEntityName="NE_ENTITY">
>                <obj-attribute name="entityType" type="java.lang.String"
> db-
> attribute-path="entityType"/>
>        </obj-entity>
>        <obj-entity name="NeEntityName"
> className="marcoproblem.data.NeEntityName"
> dbEntityName="NE_ENTITY_NAME">
>                <obj-attribute name="name" type="java.lang.String"
> db-attribute-
> path="name"/>
>        </obj-entity>
>        <db-relationship name="toNameRelation" source="NE_ENTITY"
> target="NE_NAME_RELATION" toDependentPK="true" toMany="true">
>                <db-attribute-pair source="id" target="id_entity"/>
>        </db-relationship>
>        <db-relationship name="toNameRelation" source="NE_ENTITY_NAME"
> target="NE_NAME_RELATION" toDependentPK="true" toMany="true">
>                <db-attribute-pair source="id" target="id_entity_name"/>
>        </db-relationship>
>        <db-relationship name="toEntity" source="NE_NAME_RELATION"
> target="NE_ENTITY" toMany="false">
>                <db-attribute-pair source="id_entity" target="id"/>
>        </db-relationship>
>        <db-relationship name="toEntityName" source="NE_NAME_RELATION"
> target="NE_ENTITY_NAME" toMany="false">
>                <db-attribute-pair source="id_entity_name" target="id"/>
>        </db-relationship>
>        <obj-relationship name="entityNames" source="NeEntity"
> target="NeEntityName" deleteRule="Nullify" db-relationship-
> path="toNameRelation.toEntityName"/>
>        <obj-relationship name="entities" source="NeEntityName"
> target="NeEntity" deleteRule="Nullify" db-relationship-
> path="toNameRelation.toEntity"/>
> </data-map>
>
>

Re: many to many relation

Posted by Tore Halset <ha...@pvv.ntnu.no>.
Hello.

On Dec 11, 2006, at 13:01 , marco turchi wrote:

> I've read the documentation, I created a flattened many-to-many
> relationship, but any record has been inserted inside the  
> connection table.
>
> I have the following tables and relationships:

Your mapping is wrong. I have fixed it and included it at the bottom  
of this mail.

Issuing the following java code (almost the same as yours):

         String typeEntity = "myTypeEntity";
         String term = "myTerm";

         DataContext context = DataContext.createDataContext();

         NeEntity entity = (NeEntity) context.newObject(NeEntity.class);
         NeEntityName entityName = (NeEntityName) context.newObject 
(NeEntityName.class);
         entity.setEntityType(typeEntity);
         entityName.setName(term);
         entity.addToEntityNames(entityName);

         context.commitChanges();

result in the following log:
INFO  QueryLogger: +++ Connecting: SUCCESS.
INFO  QueryLogger: Detected and installed adapter:  
org.apache.cayenne.dba.derby.DerbyAdapter
INFO  QueryLogger: SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE  
TABLE_NAME = ? FOR UPDATE [bind: 'NE_ENTITY_NAME']
INFO  QueryLogger: --- transaction started.
INFO  QueryLogger: SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE  
TABLE_NAME = ? FOR UPDATE [bind: 'NE_ENTITY']
INFO  QueryLogger: --- will run 3 queries.
INFO  QueryLogger: INSERT INTO NE_ENTITY_NAME (id, name) VALUES (?, ?)
INFO  QueryLogger: [bind: 200, 'myTerm']
INFO  QueryLogger: === updated 1 row.
INFO  QueryLogger: INSERT INTO NE_ENTITY (entityType, id) VALUES (?, ?)
INFO  QueryLogger: [bind: 'myTypeEntity', 200]
INFO  QueryLogger: === updated 1 row.
INFO  QueryLogger: INSERT INTO NE_NAME_RELATION (id_entity,  
id_entity_name) VALUES (?, ?)
INFO  QueryLogger: [bind: 200, 200]
INFO  QueryLogger: === updated 1 row.
INFO  QueryLogger: +++ transaction committed.

  - Tore.

<?xml version="1.0" encoding="utf-8"?>
<data-map project-version="2.0">
	<property name="defaultPackage" value="marcoproblem.data"/>
	<db-entity name="NE_ENTITY">
		<db-attribute name="entityType" type="VARCHAR" length="255"/>
		<db-attribute name="id" type="INTEGER" isPrimaryKey="true"  
isMandatory="true"/>
	</db-entity>
	<db-entity name="NE_ENTITY_NAME">
		<db-attribute name="id" type="INTEGER" isPrimaryKey="true"  
isMandatory="true"/>
		<db-attribute name="name" type="VARCHAR" length="150"/>
	</db-entity>
	<db-entity name="NE_NAME_RELATION">
		<db-attribute name="id_entity" type="INTEGER" isPrimaryKey="true"  
isMandatory="true"/>
		<db-attribute name="id_entity_name" type="INTEGER"  
isPrimaryKey="true" isMandatory="true"/>
	</db-entity>
	<obj-entity name="NeEntity" className="marcoproblem.data.NeEntity"  
dbEntityName="NE_ENTITY">
		<obj-attribute name="entityType" type="java.lang.String" db- 
attribute-path="entityType"/>
	</obj-entity>
	<obj-entity name="NeEntityName"  
className="marcoproblem.data.NeEntityName"  
dbEntityName="NE_ENTITY_NAME">
		<obj-attribute name="name" type="java.lang.String" db-attribute- 
path="name"/>
	</obj-entity>
	<db-relationship name="toNameRelation" source="NE_ENTITY"  
target="NE_NAME_RELATION" toDependentPK="true" toMany="true">
		<db-attribute-pair source="id" target="id_entity"/>
	</db-relationship>
	<db-relationship name="toNameRelation" source="NE_ENTITY_NAME"  
target="NE_NAME_RELATION" toDependentPK="true" toMany="true">
		<db-attribute-pair source="id" target="id_entity_name"/>
	</db-relationship>
	<db-relationship name="toEntity" source="NE_NAME_RELATION"  
target="NE_ENTITY" toMany="false">
		<db-attribute-pair source="id_entity" target="id"/>
	</db-relationship>
	<db-relationship name="toEntityName" source="NE_NAME_RELATION"  
target="NE_ENTITY_NAME" toMany="false">
		<db-attribute-pair source="id_entity_name" target="id"/>
	</db-relationship>
	<obj-relationship name="entityNames" source="NeEntity"  
target="NeEntityName" deleteRule="Nullify" db-relationship- 
path="toNameRelation.toEntityName"/>
	<obj-relationship name="entities" source="NeEntityName"  
target="NeEntity" deleteRule="Nullify" db-relationship- 
path="toNameRelation.toEntity"/>
</data-map>


Re: many to many relation

Posted by marco turchi <ma...@gmail.com>.
Hi
I've read the documentation, I created a flattened many-to-many
relationship, but any record has been inserted inside the connection table.

I have the following tables and relationships:


<db-entity name="NE_ENTITY">

<db-attribute name="entityType" type="VARCHAR" length="255"/>

<db-attribute name="id" type="INTEGER" isPrimaryKey="true"
isMandatory="true"/>

</db-entity>

<db-entity name="NE_ENTITY_NAME">

<db-attribute name="id" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="15"/>

<db-attribute name="name" type="BLOB" length="150"/>

</db-entity>

<db-entity name="NE_NAME_RELATION">

<db-attribute name="id_entity" type="INTEGER" isPrimaryKey="true"
isMandatory="true"/>

<db-attribute name="id_entity_name" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="15"/>

</db-entity>

<db-relationship name="NE_ENTITY_NAME_ARRAY" source="NE_ENTITY"
target="NE_ENTITY_NAME" toMany="true">

<db-attribute-pair source="id" target="id"/>

</db-relationship>

<db-relationship name="toEntityGenericAttribute" source="NE_ENTITY"
target="NE_ENTITY_GENERIC_ATTRIBUTE" toDependentPK="true" toMany="false">

<db-attribute-pair source="id" target="id_entity"/>

</db-relationship>

<db-relationship name="toNameRelation" source="NE_ENTITY"
target="NE_NAME_RELATION" toDependentPK="true" toMany="true">

<db-attribute-pair source="id" target="id_entity"/>

</db-relationship>

<db-relationship name="toEntityArray" source="NE_ENTITY_NAME"
target="NE_ENTITY" toDependentPK="true" toMany="false">

<db-attribute-pair source="id" target="id"/>

</db-relationship>

<db-relationship name="toNameRelation" source="NE_ENTITY_NAME"
target="NE_NAME_RELATION" toDependentPK="true" toMany="true">

<db-attribute-pair source="id" target="id_entity_name"/>

</db-relationship>

<db-relationship name="toEntity" source="NE_NAME_RELATION"
target="NE_ENTITY" toMany="false">

<db-attribute-pair source="id_entity" target="id"/>

</db-relationship>

<db-relationship name="toEntityName" source="NE_NAME_RELATION"
target="NE_ENTITY_NAME" toMany="false">

<db-attribute-pair source="id_entity_name" target="id"/>

</db-relationship>

<obj-relationship name="toEntityName" source="NeEntity"
target="NeEntityName" db-relationship-path="NE_ENTITY_NAME_ARRAY"/>

<obj-relationship name="toNameRelation" source="NeEntity"
target="NeNameRelation" db-relationship-path="toNameRelation"/>

<obj-relationship name="toEntity" source="NeNameRelation" target="NeEntity"
db-relationship-path="toEntity"/>

<obj-relationship name="toEntityName" source="NeNameRelation"
target="NeEntityName" db-relationship-path="toEntityName"/>



in Java:

NeEntity entity = (NeEntity) context.newObject(NeEntity.class);

NeEntityName entityName=(NeEntityName) context.newObject(NeEntityName.class
);

entity.setEntityType(typeEntity);

entityName.setName(term);

entity.addToToEntityName(entityName);

context.commitChanges();



but it does not insert any records in the table NE_NAME_RELATION
:-((((((((((



thanks a lot

Marco




On 12/11/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
>
> Hello.
>
> Read the documentation on flattened many-to-many  relationship.
>
> http://cwiki.apache.org/CAYDOC/cayennemodeler-flattened-
> relationships.html
> http://www.google.com/search?q=cayenne+flattened+relationship+site%
> 3Acwiki.apache.org
>
> - Tore.
>
> On Dec 10, 2006, at 18:59 , marco turchi wrote:
>
> > Hi Marcin,
> >
> > I check my model, and now the xxx.map.xml is equal to your example.
> > The new problem is inside Java.
> > you wrote:
> >
> >> Entity e = getContext().newObject(Entity.class);
> >> Name n getContext().newObject(Name.class);
> >> e.addToNames(n);
> >> getContext().commitChanges();
> >
> > but the method addToName does not accept a Name object, but a
> > NameRelation
> > object.
> > Do you know where the error is?
> >
> > Thanks a lot
> > Marco
> >
> >
>
>

Re: many to many relation

Posted by Tore Halset <ha...@pvv.ntnu.no>.
Hello.

Read the documentation on flattened many-to-many  relationship.

http://cwiki.apache.org/CAYDOC/cayennemodeler-flattened- 
relationships.html
http://www.google.com/search?q=cayenne+flattened+relationship+site% 
3Acwiki.apache.org

  - Tore.

On Dec 10, 2006, at 18:59 , marco turchi wrote:

> Hi Marcin,
>
> I check my model, and now the xxx.map.xml is equal to your example.
> The new problem is inside Java.
> you wrote:
>
>> Entity e = getContext().newObject(Entity.class);
>> Name n getContext().newObject(Name.class);
>> e.addToNames(n);
>> getContext().commitChanges();
>
> but the method addToName does not accept a Name object, but a  
> NameRelation
> object.
> Do you know where the error is?
>
> Thanks a lot
> Marco
>
>


Re: many to many relation

Posted by marco turchi <ma...@gmail.com>.
Hi Marcin,

I check my model, and now the xxx.map.xml is equal to your example.
The new problem is inside Java.
you wrote:

>Entity e = getContext().newObject(Entity.class);
>Name n getContext().newObject(Name.class);
>e.addToNames(n);
>getContext().commitChanges();

but the method addToName does not accept a Name object, but a NameRelation
object.
Do you know where the error is?

Thanks a lot
Marco




On 12/8/06, Marcin Skladaniec <ma...@ish.com.au> wrote:
>
> Hi
> just check if in your model (xxx.map.xml) you have something like that :
>
>        <db-entity name="Entity">
>                <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
>                more stuff
>        </db-entity>
>        <db-entity name="NameRelation">
>                <db-attribute name="entityId" type="INTEGER"
> isPrimaryKey="true"
> isMandatory="true"/>
>                <db-attribute name="nameId" type="INTEGER"
> isPrimaryKey="true"
> isMandatory="true"/>
>                eventually more stuff
>        </db-entity>
>                <db-entity name="Name"> <db-attribute name="id"
> type="INTEGER"
> isPrimaryKey="true" isMandatory="true"/>
>                more stuff
>        </db-entity>
>
>
> a bit further down :
>
>        <obj-entity name="Entity"
> className="Entity"  dbEntityName="Entity">
>                stuff here
>        </obj-entity>
>        <obj-entity name="NameRelation" className="NameRelation" >
>                stuff here
>        </obj-entity>
>        <obj-entity name="Name" className="Name"  dbEntityName="Name">
>                stuff here
>        </obj-entity>
>
> and now the most important:
>
>        <db-relationship name="entities" source="Name"
> target="NameRelation"
> toDependentPK="true" toMany="true">
>                <db-attribute-pair source="id" target="nameId"/>
>        </db-relationship>
>        <db-relationship name="names" source="Entity" target="NameRelation"
> toDependentPK="true" toMany="true">
>                <db-attribute-pair source="id" target="entityId"/>
>        </db-relationship>
>        <db-relationship name="entity" source="NameRelation"
> target="Entity"
> toMany="false">
>                <db-attribute-pair source="entityId" target="id"/>
>        </db-relationship>
>        <db-relationship name="name" source="NameRelation" target="Name"
> toMany="false">
>                <db-attribute-pair source="nameId" target="id"/>
>        </db-relationship>
>
>
> <obj-relationship name="entities" source="Name" target="Entity"
> deleteRule="Deny" db-relationship-path="entities.entity"/>
> <obj-relationship name="names" source="Entity" target="Name"
> deleteRule="Deny" db-relationship-path="names.name"/>
>
>
> and now in Java:
>
> Entity e = getContext().newObject(Entity.class);
> Name n getContext().newObject(Name.class);
> e.addToNames(n);
> getContext().commitChanges();
>
> This should do.
> Marcin
>
>
> On 09/12/2006, at 1:53 AM, marco turchi wrote:
>
> > Hi,
> > I'm a new Cayenne user and I'm trying to create a many to many
> > relationship.
> > This is the whole situation:
> > Entity<<->>NameRelation<<->>Name
> >
> > NameRelation has a composed key id_entity, id_name
> >
> > I create the model where
> > Entity has a "to many" relationship to Name, and a relationship that
> > forwards its key to NameRelation (the flag "To Dep PK" enabled)
> >
> > Name has  a relationship that forwards its key to NameRelation (the
> > flag "To
> > Dep PK" enabled)
> >
> > NameRelation has two "to many" relationship directed to Name and
> > Entity.
> >
> > The problem is that when I insert an element into Entity and into
> > Name, the
> > software did not insert automatically the row into NameRelation.
> >
> > maybe it is an easy question for you, but not for me... :-(
> > please, can you help me?
> >
> > Thanks a lot
> > Marco
>
> -------------------------->
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001   fax +61 2 9550 4001
>
>
>

Re: many to many relation

Posted by Marcin Skladaniec <ma...@ish.com.au>.
Hi
just check if in your model (xxx.map.xml) you have something like that :

	<db-entity name="Entity">
		<db-attribute name="id" type="INTEGER" isPrimaryKey="true"  
isMandatory="true"/>
		more stuff
	</db-entity>
	<db-entity name="NameRelation">
		<db-attribute name="entityId" type="INTEGER" isPrimaryKey="true"  
isMandatory="true"/>
		<db-attribute name="nameId" type="INTEGER" isPrimaryKey="true"  
isMandatory="true"/>
		eventually more stuff
	</db-entity>
		<db-entity name="Name">	<db-attribute name="id" type="INTEGER"  
isPrimaryKey="true" isMandatory="true"/>
		more stuff
	</db-entity>
	

a bit further down :

	<obj-entity name="Entity" className="Entity"  dbEntityName="Entity">
		stuff here
	</obj-entity>
	<obj-entity name="NameRelation" className="NameRelation" >
		stuff here
	</obj-entity>
	<obj-entity name="Name" className="Name"  dbEntityName="Name">
		stuff here
	</obj-entity>

and now the most important:

	<db-relationship name="entities" source="Name" target="NameRelation"  
toDependentPK="true" toMany="true">
		<db-attribute-pair source="id" target="nameId"/>
	</db-relationship>
	<db-relationship name="names" source="Entity" target="NameRelation"  
toDependentPK="true" toMany="true">
		<db-attribute-pair source="id" target="entityId"/>
	</db-relationship>
	<db-relationship name="entity" source="NameRelation" target="Entity"  
toMany="false">
		<db-attribute-pair source="entityId" target="id"/>
	</db-relationship>
	<db-relationship name="name" source="NameRelation" target="Name"  
toMany="false">
		<db-attribute-pair source="nameId" target="id"/>
	</db-relationship>


<obj-relationship name="entities" source="Name" target="Entity"  
deleteRule="Deny" db-relationship-path="entities.entity"/>
<obj-relationship name="names" source="Entity" target="Name"  
deleteRule="Deny" db-relationship-path="names.name"/>

	
and now in Java:

Entity e = getContext().newObject(Entity.class);
Name n getContext().newObject(Name.class);
e.addToNames(n);
getContext().commitChanges();

This should do.
Marcin


On 09/12/2006, at 1:53 AM, marco turchi wrote:

> Hi,
> I'm a new Cayenne user and I'm trying to create a many to many  
> relationship.
> This is the whole situation:
> Entity<<->>NameRelation<<->>Name
>
> NameRelation has a composed key id_entity, id_name
>
> I create the model where
> Entity has a "to many" relationship to Name, and a relationship that
> forwards its key to NameRelation (the flag "To Dep PK" enabled)
>
> Name has  a relationship that forwards its key to NameRelation (the  
> flag "To
> Dep PK" enabled)
>
> NameRelation has two "to many" relationship directed to Name and  
> Entity.
>
> The problem is that when I insert an element into Entity and into  
> Name, the
> software did not insert automatically the row into NameRelation.
>
> maybe it is an easy question for you, but not for me... :-(
> please, can you help me?
>
> Thanks a lot
> Marco

-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001