This is not a new code (so not 5.0 specific), and it even has a comment 
questioning such logic :) 

// 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. 

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 PM, Ricardo Parada <[email protected]> wrote:
> 
> Hello,
> 
> I wrote a converter to convert our eomodels from EOF to Cayenne-project.xml 
> and data maps .map.xml
> 
> So far so good. However, I seem to be running into a problem for cross data 
> map relationships. 
> 
> I’m using 5.0-M1. 
> 
> When I’m creating the ObjRelationship I call:
> 
> objRel.setTargetEntityName(targetObjEntity);
> 
> If I then call objRel.getTargetEntityName() it returns the correct target 
> entity name.  
> 
> However, if I call objRel.getTargetEntity() it returns null. 
> 
> 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. 
> 
> 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. 
> 
> Is this a bug in 5.0-M1 or am I missing something when creating my 
> ObjRelationship programmatically. 
> 
> I could put all eomodels that have cross eomodel relationships into the same 
> data map to avoid this problem. 
> 
> 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. 
> 
> Thank you all in advance. 
> Ricardo Parada 
> 
> 

Reply via email to