Tomcat will not deploy when cuba-core is part of classpath


I have a Frame, called Holiday (I’ll call it HolidayFrame). This frame allows creating instances of the Entity called Holiday. Every Holiday instance has one Person attached to it (ManyToOne) relationship. For every user, that will be able to log in to this page will have one instance of Person mapped to, these aren’t in explicit relationship, we, the operators will make sure, that the Name of this user and the Name of the corresponding Person will match.

Now, the interesting part: In this HolidayFrame, I want the Person to be attached to this Holiday instance automatically, and that Person to be the one corresponding to the User logged in, creating this Holiday instance.

So, if I’m called XY, I’ll have a instance of Person, with the name XY, and there will be a user with the name XY. I want to create a new Holiday, but I’ll not be able to choose the Person to be attached to this new instance, still it will be written to the DB with the Person called XY attached to it.

What i need to do is in the save function, I get given Person, and add it to the new Holiday instance. I wanted to use the EntityManager, from javax.persistence package, but I needed to realise that I can’t inject it from my HolidayFrame class.

------- TL;DR -------- The problem comes from here

After, I tried to use the Persistence interface, since I can get a EntityManager from that, but I need the cuba-core.jar for this class to be available. So I went to Project properties > Advanced > Web Module and added the dependecy com.haulmont.cuba:cuba-core:6.6.1.
Then, I added this .jar to the classpath of the Web Module in IntelliJ (it gave me this suggestion), and it was cool, I wrote the code, and it compiled, and I started Tomcat, who said that:

02-Aug-2017 13:59:27.942 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class com.haulmont.cuba.web.sys.WebAppContextLoader
 org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [cuba-web-spring.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'cuba_NumberIdSource' for bean class [com.haulmont.cuba.client.sys.NumberIdSourceClientImpl] conflicts with existing, non-compatible bean definition of same name and class [com.haulmont.cuba.core.sys.NumberIdSourceImpl]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(
	at com.haulmont.cuba.core.sys.CubaClassPathXmlApplicationContext.<init>(
	at com.haulmont.cuba.core.sys.AbstractAppContextLoader.createApplicationContext(
	at com.haulmont.cuba.core.sys.AbstractAppContextLoader.initAppContext(
	at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(
	at org.apache.catalina.core.StandardContext.listenerStart(
	at org.apache.catalina.core.StandardContext.startInternal(
	at org.apache.catalina.util.LifecycleBase.start(
	at org.apache.catalina.core.ContainerBase.addChildInternal(
	at org.apache.catalina.core.ContainerBase.addChild(
	at org.apache.catalina.core.StandardHost.addChild(
	at org.apache.catalina.startup.HostConfig.deployDirectory(
	at org.apache.catalina.startup.HostConfig$
	at java.util.concurrent.Executors$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'cuba_NumberIdSource' for bean class &#91;com.haulmont.cuba.client.sys.NumberIdSourceClientImpl&#93; conflicts with existing, non-compatible bean definition of same name and class &#91;com.haulmont.cuba.core.sys.NumberIdSourceImpl&#93;
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(
	at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(
	... 30 more

And of course, the server started, but the app didn’t. It can be solved by destroying every clue of cuba-core’s existence completely from the project, but now I don’t have the Persistence interface.

What should I do to avoid this? Am I approaching it from the wrong direction?

Thanks in advance,


EntityManager cannot be used at the client tier, it belongs to the middleware only. And please don’t introduce any new dependencies between CUBA modules, it will break everything as you see. Additional dependencies are only for using external libraries.

The universal mechanism of working with data on all tiers is DataManager. See also DataManager vs. EntityManager and Data Manipulation sample project (it is also available on the Samples tab in Studio).

oh…my.god…boy do I feel stupid now.

I literally tried everything else, because “I need entities, not simple data”… yeah, pretty much solved it in 15mins where 10mins were because of a wrong query string

Thank you very much