Re: Cross data map relationships

Andrus Adamchik <[email protected]> Tue, 14 Oct 2025 16:44:52 -0400
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
This is not a new code (so not 5.0 specific), and it even has a comment =
questioning such logic :)=20

// looking up a target entity ensures that bogus names are not saved...
// whether this is good or bad is debatable, as users may want to point =
to
// non-existent entities on purpose.

So anyways, the way around is to load all DataMaps involved in a single =
MappingNamespace to satisfy inter-map dependencies. Usually this would =
be an EntityResolver. Once you load multiple DataMaps in an =
EntityResolver, you can save them one by one.=20

There's also a higher-level API for managing multiple Cayenne project =
resources (specifically, saving them to files) in the "cayenne-project" =
module. Though this may be an overkill.

Andrus


> On Oct 14, 2025, at 3:29=E2=80=AFPM, Ricardo Parada =
<[email protected]> wrote:
>=20
> Hello,
>=20
> I wrote a converter to convert our eomodels from EOF to =
Cayenne-project.xml and data maps .map.xml
>=20
> So far so good. However, I seem to be running into a problem for cross =
data map relationships.=20
>=20
> I=E2=80=99m using 5.0-M1.=20
>=20
> When I=E2=80=99m creating the ObjRelationship I call:
>=20
> objRel.setTargetEntityName(targetObjEntity);
>=20
> If I then call objRel.getTargetEntityName() it returns the correct =
target entity name. =20
>=20
> However, if I call objRel.getTargetEntity() it returns null.=20
>=20
> I debugged the code and I can see that getTargetEntity() is looking =
for the target entity name in the data map corresponding to the source =
ObjEntity. And it does not find it and returns null for that reason.=20
>=20
> As a result of that, when I call encodeAsXML() on objRel I see that =
the XML is missing the target attribute in the obj-relationship xml tag.=20=

>=20
> Is this a bug in 5.0-M1 or am I missing something when creating my =
ObjRelationship programmatically.=20
>=20
> I could put all eomodels that have cross eomodel relationships into =
the same data map to avoid this problem.=20
>=20
> But when I create it in Cayenne Modeler 4.3.3 it seems to work. I see =
the obj-relationship in the XML have target correctly set.=20
>=20
> Thank you all in advance.=20
> Ricardo Parada=20
>=20
>=20