Discussion:
[Middlegen-user] VALUEOBJECT_REFACTORING_BRANCH and relations
Markus Härnvi
2003-09-12 17:09:51 UTC
Permalink
Hi!

I'm trying out Middlegen and the Value Object branch. I can't find any methods
in the entity facade for adding child objects. I read in JIRA
(http://jira.codehaus.org/secure/ViewIssue.jspa?key=MIDDLEGEN-3) that middlegen
currently can't handle relations automatically.

But how do I add/list/remove related entities through the facade in it's current
form? Lets say I have a Person object that has a 1..* relation to some Address
objects.

Thanks in advance!

/Markus
Eivind Waaler
2003-09-15 05:01:22 UTC
Permalink
As far as I remember, we made the update methods in the facade take the
light version of the value object. That means to update relationships you
have to update the actual id on the light value object and run update with
the facade:

AddressValue address =3D addressFacade.findByPrimaryKey(aId);
PersonValue person =3D personFacade.findByPrimaryKey(pId);
person.setAddressIdFk(address.getPrimaryKey());
person =3D personFacade.update(person);

Something like that.. Kind of unconvenient, but at least this will work.

=2Eeivind
=20
Hi!
=20
I'm trying out Middlegen and the Value Object branch. I can't find any me=
thods
in the entity facade for adding child objects. I read in JIRA
(http://jira.codehaus.org/secure/ViewIssue.jspa?key=3DMIDDLEGEN-3) that m=
iddlegen
currently can't handle relations automatically.
=20
But how do I add/list/remove related entities through the facade in it's =
current
form? Lets say I have a Person object that has a 1..* relation to some Ad=
dress
objects.
=20
Thanks in advance!
=20
/Markus
=20
=20
=20
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
=20
Markus Härnvi
2003-09-17 10:07:07 UTC
Permalink
Hi!

I got the 1..* working. Thanks.

LogMessageLightValue logValue =
logFacade.create("Foo");
logDetail = new LogDetailLightValue();
logDetail.setLogid(logValue.getLogid());
logDetail = detailFacade.create(logDetail);

Now I have a many-to-many relation between two entity beans (Group and Node). I
am using a mapping table to handle the relation. Middlegen finds the mapping
table and everything seems OK.

I can get the related beans through the facade, if I work with pre-existing data
in the tables:

Collection groups = groupFacade.findByPrimaryKey(pk);
...
NodeLightValue [] nodes = group.getNodes();

But how do I create new relations? I can add NodeLightValue to GroupValue:

groupValue.addNode(node);
groupFacade.update(groupValue);

But the update() method in the facade only take GroupLightValue, and the light
VO doesn't contain the relations.

/Markus
Post by Eivind Waaler
As far as I remember, we made the update methods in the facade take the
light version of the value object. That means to update relationships you
have to update the actual id on the light value object and run update with
AddressValue address = addressFacade.findByPrimaryKey(aId);
PersonValue person = personFacade.findByPrimaryKey(pId);
person.setAddressIdFk(address.getPrimaryKey());
person = personFacade.update(person);
Something like that.. Kind of unconvenient, but at least this will work.
.eivind
Post by Markus Härnvi
Hi!
I'm trying out Middlegen and the Value Object branch. I can't find any
methods
Post by Markus Härnvi
in the entity facade for adding child objects. I read in JIRA
(http://jira.codehaus.org/secure/ViewIssue.jspa?key=MIDDLEGEN-3) that
middlegen
Post by Markus Härnvi
currently can't handle relations automatically.
But how do I add/list/remove related entities through the facade in it's
current
Post by Markus Härnvi
form? Lets say I have a Person object that has a 1..* relation to some
Address
Post by Markus Härnvi
objects.
Thanks in advance!
/Markus
Eivind Waaler
2003-09-17 11:54:04 UTC
Permalink
Hmm, good point.

I think the only way to do it with the current version is to reverse it:

node.setGroupId(groupId);
nodeFacade.update(node);

Don't if this would work for your example?

I suggest you log this as a bug in the JIRA issue tracker. It has a
separate version called 2.0-beta-2-VALUEOBJECT_REFACTORING_BRANCH:

http://jira.codehaus.org/secure/BrowseProject.jspa?id=3D10110

=2Eeivind
=20
Hi!
=20
I got the 1..* working. Thanks.=20
=20
LogMessageLightValue logValue =3D
logFacade.create("Foo");
logDetail =3D new LogDetailLightValue();
logDetail.setLogid(logValue.getLogid());
logDetail =3D detailFacade.create(logDetail);
=20
Now I have a many-to-many relation between two entity beans (Group and No=
de). I
am using a mapping table to handle the relation. Middlegen finds the mapp=
ing
table and everything seems OK.
=20
I can get the related beans through the facade, if I work with pre-existi=
ng data
=20
Collection groups =3D groupFacade.findByPrimaryKey(pk);
...
NodeLightValue [] nodes =3D group.getNodes();
=20
But how do I create new relations? I can add NodeLightValue to GroupValue=
:=20
=20
groupValue.addNode(node);=20
groupFacade.update(groupValue);
=20
But the update() method in the facade only take GroupLightValue, and the =
light
VO doesn't contain the relations.=20
=20
/Markus
=20
Post by Eivind Waaler
As far as I remember, we made the update methods in the facade take the
light version of the value object. That means to update relationships y=
ou
Post by Eivind Waaler
have to update the actual id on the light value object and run update w=
ith
Post by Eivind Waaler
=20
AddressValue address =3D addressFacade.findByPrimaryKey(aId);
PersonValue person =3D personFacade.findByPrimaryKey(pId);
person.setAddressIdFk(address.getPrimaryKey());
person =3D personFacade.update(person);
=20
Something like that.. Kind of unconvenient, but at least this will work=
=2E
Post by Eivind Waaler
=20
.eivind
=20
=20
=20
Hi!
=20
I'm trying out Middlegen and the Value Object branch. I can't find an=
y
Post by Eivind Waaler
methods
in the entity facade for adding child objects. I read in JIRA
(http://jira.codehaus.org/secure/ViewIssue.jspa?key=3DMIDDLEGEN-3) th=
at
Post by Eivind Waaler
middlegen
currently can't handle relations automatically.
=20
But how do I add/list/remove related entities through the facade in i=
t's
Post by Eivind Waaler
current
form? Lets say I have a Person object that has a 1..* relation to som=
e
Post by Eivind Waaler
Address
objects.
=20
Thanks in advance!
=20
/Markus
=20
=20
=20
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
=20
Loading...