bootique / bootique-cayenne

Cayenne Integration Module for Bootique
https://bootique.io
Apache License 2.0
5 stars 8 forks source link

Implicit config should not be loaded when there is an explicit Bootique config of maps #54

Closed andrus closed 6 years ago

andrus commented 6 years ago

Given a project with default name cayenne-project.xml and the following YAML config, we get an error similar to the one below. It happens because Cayenne loads each DataMap twice - once via implicit default project, and the second time - based on the "maps" section.

We should ignore the default project if maps are present explicitly (perhaps with a warning in the logs).

cayenne:
  createSchema: true
  maps:
    - location: classpath:dm1.map.xml
      name: map1
      datasource: ds1
    - location: classpath:dm2.map.xml
      name: map2
      datasource: ds2

Error:

org.apache.cayenne.CayenneRuntimeException: [v.4.0.RC1 Apr 18 2018 13:10:58] Can't perform lookup. There is more than one ObjEntity mapped to io.bootique.cayenne.dm1.Entity1

    at org.apache.cayenne.map.MappingCache.getObjEntity(MappingCache.java:175)
    at org.apache.cayenne.map.ProxiedMappingNamespace.getObjEntity(ProxiedMappingNamespace.java:73)
    at org.apache.cayenne.map.EntityResolver.getObjEntity(EntityResolver.java:494)
    at org.apache.cayenne.access.DataContext.newObject(DataContext.java:469)
erdinckocaman commented 5 years ago

This error still persists even I upgrade to v1.0. I have to remove data map definitions from cayenne project file to run my application successfully. If they stays in cayenne project file, it gives error.

Interesting point is that I can see your fix is in charge by putting debugpoint but still gets the same error message, weird.

aarrsseni commented 5 years ago

Hi, I've tried to check this issue again. For me this fix is working. I read your mail on bootique mail list and had an assumption: maybe for some reason you added cayenne-project in code (for example CayenneModule.extend(binder).addProject("cayenne-project.xml")). If I did it this bug appeared. Also it happened when I had duplicated entities in different datamaps but I think you've checked this.

erdinckocaman commented 5 years ago

Ok, I checked the code, found similar line like you mentioned 'CayenneModule.extend(binder)...' After removing that, it seems ok, thanks.

andrus commented 5 years ago

So I guess not an issue after all, but I wish the errors were a bit more transparent. I opened #67 to take another look and see if we can improve the diagnostics.