Does CUBA support JPA Converter class with `autoApply=true`?

I wanted to apply a custom @Converter to all entity attributes of type Boolean, so the first thing I tried was a converter with this signature:

@Converter(autoApply = true)
public class BooleanToIntegerConverter implements AttributeConverter<Boolean, Integer> {

and I added it to the persistence-unit.

As you know autoApply comes in handy when you want all your attributes magically pick the same converter, without the error prone task to add the @Convert annotation to EVERY attribute of that type…

But when I tried this in a CUBA project, the application failed at startup with the following exception:

2018-12-15 00:06:05.346 DEBUG [localhost-startStop-1] - Initialize anonymous session
2018-12-15 00:06:05.908 INFO [localhost-startStop-1/app-core/server] - Loading DB-stored app properties cache
2018-12-15 00:06:06.507 DEBUG [localhost-startStop-1/app-core/server] - Unable to find user: anonymous
2018-12-15 00:06:06.518 ERROR [localhost-startStop-1] com.haulmont.cuba.core.sys.AbstractWebAppContextLoader - Error initializing application
java.lang.RuntimeException: Unable to create anonymous session. It is required for system to start
 at ~[cuba-core-6.10.5.jar:6.10.5]
 at ~[cuba-core-6.10.5.jar:6.10.5]
 at com.haulmont.cuba.core.sys.AppContext.startContext( ~[cuba-global-6.10.5.jar:6.10.5]
 at com.haulmont.cuba.core.sys.AppContext$Internals.startContext( ~[cuba-global-6.10.5.jar:6.10.5]
 at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized( ~[cuba-global-6.10.5.jar:6.10.5]
 at org.apache.catalina.core.StandardContext.listenerStart( [catalina.jar:8.5.33]
 at org.apache.catalina.core.StandardContext.startInternal( [catalina.jar:8.5.33]
 at org.apache.catalina.util.LifecycleBase.start( [catalina.jar:8.5.33]
 at org.apache.catalina.core.ContainerBase.addChildInternal( [catalina.jar:8.5.33]
 at org.apache.catalina.core.ContainerBase.addChild( [catalina.jar:8.5.33]
 at org.apache.catalina.core.StandardHost.addChild( [catalina.jar:8.5.33]
 at org.apache.catalina.startup.HostConfig.deployDirectory( [catalina.jar:8.5.33]
 at org.apache.catalina.startup.HostConfig$ [catalina.jar:8.5.33]
 at java.util.concurrent.Executors$ [na:1.8.0_181]
 at [na:1.8.0_181]
 at java.util.concurrent.ThreadPoolExecutor.runWorker( [na:1.8.0_181]
 at java.util.concurrent.ThreadPoolExecutor$ [na:1.8.0_181]
 at [na:1.8.0_181]
Caused by: Login o password errati 'anonymous'
 at ~[cuba-core-6.10.5.jar:6.10.5]
 at ~[cuba-core-6.10.5.jar:6.10.5]
 at ~[cuba-core-6.10.5.jar:6.10.5]
 at ~[cuba-core-6.10.5.jar:6.10.5]
 at ~[cuba-core-6.10.5.jar:6.10.5]
 ... 17 common frames omitted

If I simply remove autoApply = true from the @Convert annotation, the error disappears and the project starts just fine. The problem is that now I need to scan every Boolean attribute in my entities, and put @Convert on each of them: not a funny task :wink:

Is it a known issue, or do you know some workaround to let me use autoApply = true?


ok, it seems that the converter is now applied to all Boolean attributes, even outside MY persistence-unit, so it gets picked up even for the cuba persistence unit.

And for that reason now queries on system entities (like User) that rely on Boolean attributes are failing, because my converter kicks in.

I was convinced that an autoApply converter works in isolation inside the persistence-unit where it is registered, but it seems I was wrong…
So the real question now is: Do you know if I can isolate the converter only to my own persistence-unit, keeping it with autoApply=true ?


Hi Paolo,
In fact, your application uses a single persistence unit for each database (Data Store in CUBA terms), no matter how many application components with own persistence.xml files you use. All of them are merged into one on the application startup, see the joined persistence.xml in tomcat/work/app-core folder.
Please create an issue, we’ll think what we can do.