Re: many to many relation
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
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 [EMAIL PROTECTED] 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
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
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 [EMAIL PROTECTED] 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
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
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