You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Mauro Carniel <ma...@tinet.it> on 2008/04/17 15:49:45 UTC

help on saving obj using relations

Hi!

Maybe someone in the past has already met this issue, so sorry if I ask it again!
I've got 3 tables: employee, depts and tasks having 2 fk: one from employees to depts and  one from employees to tasks.
I've modeled both tables and relations using modeler.

After that I created a simple application when I want to create a detail form for an employee having info about emp, his task and dept.
When I use this form in "insert mode", I create an emp value object having two relations to dept and task "inner" value objects.
The problem arises when I commit that obj: Cayenne attempts to insert one record to task, one to dept and finally one for emp and this is wrong for me:
I want it only inserts one record for emp: task and dept already exists in the db!

For instance, Hibernate ORM provides an attribute for xml descriptor about relation between two objs: using this attribute it is possible to avoid inner value objects insertion (i.e. value objects related to the main value object, emp...)
How can I specify the same concept using Cayenne?

Thanks for the help,
Regards,
Mauro

Re: help on saving obj using relations

Posted by Michael Gentry <bl...@gmail.com>.
I looked at:

http://oswing.svn.sourceforge.net/viewvc/oswing/trunk/srcdemo/demo36/auto/_EmpVO.java?revision=214&view=markup

And I don't believe you have modeled your relationships correctly.
You manually created a get/setDept() and get/setTask() in the
subclass:

http://oswing.svn.sourceforge.net/viewvc/oswing/trunk/srcdemo/demo36/EmpVO.java?revision=214&view=markup

However, those should be generated by Cayenne in the parent
(_EmpVO.java) class.  At least if you have your relationships modeled
correctly.  Go back into the modeler and look under the Relationship
tab for both your DbEntity and your ObjEntity and make sure they are
defined in each place.  You may need to synchronize your ObjEntity
with your DbEntity (click the sync button).  After you get your
relationships defined, regenerate your superclasses.

/dev/mrg



On Thu, Apr 17, 2008 at 11:03 AM, Gustav Weber <gu...@yahoo.com> wrote:
> I guess Mauro forgot to mention an important aspect:
>
>  The situation appeared while integrating Cayenne with
>  OpenSwing:
>  http://oswing.sourceforge.net/
>
>  and the problem he describes can be seen/reproduced
>  from the code example in "srcdemo/demo36" from the
>  project's Sourceforge SVN repository:
>  http://sourceforge.net/projects/oswing/
>
>  regards,
>  Gustav.
>
>
>
>       ____________________________________________________________________________________
>  Be a better friend, newshound, and
>  know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>

Re: help on saving obj using relations

Posted by Gustav Weber <gu...@yahoo.com>.
I guess Mauro forgot to mention an important aspect:

The situation appeared while integrating Cayenne with
OpenSwing:
http://oswing.sourceforge.net/

and the problem he describes can be seen/reproduced
from the code example in "srcdemo/demo36" from the
project's Sourceforge SVN repository:
http://sourceforge.net/projects/oswing/

regards,
Gustav. 


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ