Nanik,
Working with objects is the whole point of using an Object/Relational
tool, right ;-). So I don't see how the code below could be a problem.
It is very straightforward and simple, isn't it. The only thing I can
suggest to improve it is maybe committing both groups and a module only
once and in the same transaction (if this makes sense from your app
standpoint). Maybe this is what you were looking for?
Module module = (Module)ctxt.createAndRegisterNewObject("Module");
module.setModulename("CUSTOMER");
Groups group1 = (Groups)ctxt.createAndRegisterNewObject("Groups");
group1.setGroupname("ADMIN");
Groups group2 = (Groups)ctxt.createAndRegisterNewObject("Groups");
group2.setGroupname("USER");
module.addToGroupsArray(group1);
module.addToGroupsArray(group2);
ctxt.commitChanges();
Andrus
Nanik Tolaram wrote:
> Hi,
>
> Thanks for the reply. Actually the relationship is one-to-many (MODULES(1)
> and GROUP(many)). What I'm looking for is actually if we are inserting a new
> record into the MODULES table how can I insert a record into the GROUP table
> without creating new object for every new record that I want to insert. For
> example if I insert using the following code,
>
> ....
> ....
> group.setGroupname("ADMIN");
>
> module.setModulename("CUSTOMER");
> module.addToGroupsArray(group);
>
> ctxt.commitChanges(Level.DEBUG);
>
> ....
> ....
>
> With the code above the GROUP table will have a record of ADMIN and that
> particular is linked through the foreign key with te primary key of the
> MODULE table (containing the data CUSTOMER). Now, how do I insert additional
> record into the GROUP table without creating a new group object, something
> like the following
>
>
> ....
> ....
> group.setGroupname("ADMIN");
>
> module.setModulename("CUSTOMER");
> module.addToGroupsArray(group);
>
> ctxt.commitChanges(Level.DEBUG);
>
>
> group.setGroupname("USER")
> module.addToGroupsArray(group);
> ctxt.commitChanges(Level.DEBUG);
>
> ....
> ....
>
> Sorry if my question is bit long winded, just want to make sure I understand
> what I'm doing :)
>
> Thanks
> Nanik
This archive was generated by hypermail 2.0.0 : Sun Mar 02 2003 - 13:54:27 EST