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>


Reply via email to