cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcin Skladaniec <>
Subject Re: many to many relation
Date Fri, 08 Dec 2006 22:59:18 GMT
just check if in your model ( you have something like that :

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

a bit further down :

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

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 name="names" source="Entity" target="NameRelation"  
toDependentPK="true" toMany="true">
		<db-attribute-pair source="id" target="entityId"/>
	<db-relationship name="entity" source="NameRelation" target="Entity"  
		<db-attribute-pair source="entityId" target="id"/>
	<db-relationship name="name" source="NameRelation" target="Name"  
		<db-attribute-pair source="nameId" target="id"/>

<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=""/>

and now in Java:

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

This should do.

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

Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001

View raw message