Results 1 to 3 of 3

Thread: With Spring Roo unable to map two entities together without exception

  1. #1
    Join Date
    Sep 2011
    Posts
    2

    Default With Spring Roo unable to map two entities together without exception

    I have tired to search in this forum and everywhere with google for my problem solution, but nothing has helped, so: I'm creating very simple web application with spring roo v1.2.3. My log.roo file:

    Code:
    project --topLevelPackage com.test --projectName springRooJPA --java 6 --packaging JAR
    jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY 
    entity jpa --class ~.domain.Person
    field string --fieldName name
    entity jpa --class ~.domain.Community
    field string --fieldName title
    web jsf setup --library PRIMEFACES --implementation APACHE_MYFACES --theme EGGPLANT 
    web jsf all --package ~.jsf
    When application starts - no exceptions are thrown and website works fine. After that I'm trying to reach some mapping between entities, so I execute this command:
    Code:
    field set --class ~.domain.Person --fieldName communities --type ~.domain.Community --cardinality ONE_TO_MANY --mappedBy personCommunities
    I have tried many variants to reach such mapping between entities: without property --mappedBy; --carcinality MANY_TO_MANY and executed two field set commands, to both entities, but all these variants made the same exception at application startup:
    Code:
    [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\Java\workspaces\spring_roo_tests\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\springRooJPA\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
    	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:286)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
    All my configuration files are unchanget (generated by Spring Roo). This is persistance.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
                <property name="hibernate.hbm2ddl.auto" value="create"/>
                <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
                <property name="hibernate.connection.charSet" value="UTF-8"/>
            </properties>
        </persistence-unit>
    </persistence>
    So why is rising that exception when some mapping between two entities is made and how to reach such mapping successfully?

  2. #2
    Join Date
    Sep 2011
    Posts
    2

    Default

    So finally the problem is solved. When such exception (Error creating bean with name 'entityManagerFactory') was throwed - mapping command was wrong (it was sometimes, when I tried many different Spring Roo commands). When I made this Spring Roo command:
    Code:
    field set --class ~.domain.Person --fieldName communities --type ~.domain.Community --cardinality ONE_TO_MANY
    starting project was throwing errors:
    Code:
    2013-01-09 00:15:26,755 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: alter table person_communities drop constraint FKB4F94C5D55425C65
    
    2013-01-09 00:15:26,755 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - user lacks privilege or object not found: PUBLIC.PERSON_COMMUNITIES
    
    2013-01-09 00:15:26,755 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: alter table person_communities drop constraint FKB4F94C5DC2C99695
    
    2013-01-09 00:15:26,755 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - user lacks privilege or object not found: PUBLIC.PERSON_COMMUNITIES
    Appears that such errors doesn't mean any problem, they shows only when --database HYPERSONIC_IN_MEMORY is used. But with these errors everything works fine (using any database). When switching to real database (MySQL or Postgresql) such errors doesn't show.

  3. #3
    Join Date
    Aug 2010
    Location
    Goteborg, Sweden
    Posts
    434

    Default

    Quote Originally Posted by Rootis View Post

    Code:
    field set --class ~.domain.Person --fieldName communities --type ~.domain.Community --cardinality ONE_TO_MANY --mappedBy personCommunities
    So why is rising that exception when some mapping between two entities is made and how to reach such mapping successfully?
    You also need to link back the MANY class to the ONE class with

    Code:
    field reference --class ~.domain.Community --fieldName person --type ~.domain.Person --cardinality MANY_TO_ONE
    in order for the JPA relationship to be complete.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •