Nanik,
First according to your DataMap XML and code,, module has multiple
groups, so your description contradicts the map: Module has multiple
Groups, not the other way around, right?
You are saying "I want to a similar record but different foreign key in
GROUP table", but you can't a foreign key without a corresponding
primary key in MODULES. So having an instance of Module object, either
new or existing one (and a corresponding MODULES record) is the only
way, if I correctly understand what you are trying to do here.
This has nothing to do with Cayenne, this is simply how database
relationships work.
Andrus
Nanik Tolaram wrote:
> Hi,
>
> I have a 1-to-many relationship between GROUPS and MODULE (GROUP
> (1)----(N) MODULE). I want to a similar record but different foreign key
> in GROUP table, I have done like the following
>
>
> Groups group= (Groups)ctxt.createAndRegisterNewObject("Groups");
> Module module = (Module)ctxt.createAndRegisterNewObject("Module");
>
> group.setGROUPID(new Integer(1));
> group.setGroupname("ADMIN");
>
> module.setModulename("CUSTOMER");
> module.addToGroupsArray(group);
>
> ctxt.commitChanges(Level.DEBUG); // commit
>
>
> Module module1 = (Module)ctxt.createAndRegisterNewObject("Module");
> Groups group1= (Groups)ctxt.createAndRegisterNewObject("Groups");
>
> group1.setGROUPID(new Integer(1));
> group1.setGroupname("ADMIN");
>
> module1.setModulename("PRODUCT");
> module1.addToGroupsArray(group1);
>
> ctxt.commitChanges(Level.DEBUG); // commit
>
> and the following is the datamap.map.xml config file,
>
> <?xml version="1.0" encoding="UTF-8"?>
> <data-map project-version="1.0">
>
> <db-entity name="USERS">
> <db-attribute name="login_name" type="CHAR"
> isMandatory="true" length="20"/>
> <db-attribute name="userid" type="INTEGER"
> isPrimaryKey="true" isMandatory="true"/>
> </db-entity>
>
> <db-entity name="GROUPS">
> <db-attribute name="GROUPID" type="INTEGER"
> length="4"/>
> <db-attribute name="groupname" type="CHAR"
> length="50"/>
> <db-attribute name="MODULEID" type="INTEGER"
> length="4"/>
> </db-entity>
>
> <db-entity name="MODULE">
> <db-attribute name="MODULEID" type="INTEGER"
> isPrimaryKey="true" isMandatory="true"/>
> <db-attribute name="modulename" type="CHAR"
> length="50"/>
> </db-entity>
>
>
>
> <obj-entity name="Groups" className="Groups"
> dbEntityName="GROUPS">
> <obj-attribute name="GROUPID"
> type="java.lang.Integer" db-attribute-name="GROUPID"/>
> <obj-attribute name="groupname"
> type="java.lang.String" db-attribute-name="groupname"/>
> </obj-entity>
>
> <obj-entity name="Users" className="Users"
> dbEntityName="USERS">
> <obj-attribute name="login_name"
> type="java.lang.String" db-attribute-name="login_name"/>
> </obj-entity>
>
> <obj-entity name="Module" className="Module"
> dbEntityName="MODULE">
> <obj-attribute name="modulename"
> type="java.lang.String" db-attribute-name="modulename"/>
> </obj-entity>
>
>
>
>
> <db-relationship name="groupsArray" source="MODULE"
> target="GROUPS" toDependentPK="false" toMany="true">
> <db-attribute-pair source="MODULEID"
> target="MODULEID"/>
> </db-relationship>
>
> <db-relationship name="toGroups" source="GROUPS"
> target="MODULE" toDependentPK="false" toMany="false">
> <db-attribute-pair source="MODULEID"
> target="MODULEID"/>
> </db-relationship>
>
>
>
>
> <obj-relationship name="groupsArray" source="Module"
> target="Groups" toMany="true" deleteRule="Nullify">
> <db-relationship-ref source="MODULE"
> target="GROUPS" name="groupsArray"/>
> </obj-relationship>
>
> <obj-relationship name="toGroups" source="Groups"
> target="Module" toMany="false" deleteRule="Nullify">
> <db-relationship-ref source="GROUPS"
> target="MODULE" name="toGroups"/>
> </obj-relationship>
>
> </data-map>
>
> Are there any other way to make things easier if I want to insert same
> record with different foreign key ?
>
> Thanks
> Nanik
>
>
>
>
>
>
This archive was generated by hypermail 2.0.0 : Sun Mar 02 2003 - 11:15:20 EST