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

Hello,

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(XmlBeanDefinitionReader.java:414)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:612)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:513)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
	at com.haulmont.cuba.core.sys.CubaClassPathXmlApplicationContext.<init>(CubaClassPathXmlApplicationContext.java:27)
	at com.haulmont.cuba.core.sys.AbstractAppContextLoader.createApplicationContext(AbstractAppContextLoader.java:79)
	at com.haulmont.cuba.core.sys.AbstractAppContextLoader.initAppContext(AbstractAppContextLoader.java:56)
	at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:73)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1107)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1841)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
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(ClassPathBeanDefinitionScanner.java:320)
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:259)
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:87)
	at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:172)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
	... 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,
Ropi

Hi,

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