Announcement Announcement Module
Collapse
No announcement yet.
MappingException in brand new project ... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MappingException in brand new project ...

    Hey all,

    I'm using Roo 1.1.4 (No updates)

    I create a project and use Hibernate & Hypersonic (In Memory) for database.

    I create two classes and their supporting web controllers using entity and controller calls. (UserPerson & UserGroup)

    Finally I add a "UserPerson" field to the UserGroup class.

    I then do a perform package and try deploying it to Tomcat (6.0.29) and when it tries to deploy it presents the following error:

    2011-06-15 16:07:25,286 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in file [/opt/apache-tomcat-6.0.29/webapps/test/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in file [/opt/apache-tomcat-6.0.29/webapps/test/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.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1325)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 47)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4135)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4630)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployWAR(H ostConfig.java:905)
    at org.apache.catalina.startup.HostConfig.deployWARs( HostConfig.java:740)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:500)
    at org.apache.catalina.startup.HostConfig.check(HostC onfig.java:1345)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:303)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.backgroundP rocess(ContainerBase.java:1337)
    at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.processChildren(ContainerBase.ja va:1601)
    at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.processChildren(ContainerBase.ja va:1610)
    at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.run(ContainerBase.java:1590)
    at java.lang.Thread.run(Thread.java:680)
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in file [/opt/apache-tomcat-6.0.29/webapps/test/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.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1420)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:322)
    ... 31 more
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityMan agerFactory(Ejb3Configuration.java:915)
    at org.hibernate.ejb.HibernatePersistence.createConta inerEntityManagerFactory(HibernatePersistence.java :74)
    at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:225)
    at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:308)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417)
    ... 38 more
    Caused by: org.hibernate.MappingException: Could not determine type for: com.example.domain.UserPerson, at table: user_group, for columns: [org.hibernate.mapping.Column(participant)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleVa lue.java:306)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleVa lue.java:290)
    at org.hibernate.mapping.Property.isValid(Property.ja va:217)
    at org.hibernate.mapping.PersistentClass.validate(Per sistentClass.java:464)
    at org.hibernate.mapping.RootClass.validate(RootClass .java:235)
    at org.hibernate.cfg.Configuration.validate(Configura tion.java:1335)
    at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1838)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityMan agerFactory(Ejb3Configuration.java:906)
    ... 43 more


    Same exact path in Roo 1.1.2 results in a normal project displays.

    Also, primitive fields (or String) behave properly. (e.g. "private int age" will not cause similar error.)

    POJO classes are as follows:

    package com.example.domain;

    import org.springframework.roo.addon.entity.RooEntity;
    import org.springframework.roo.addon.javabean.RooJavaBean ;
    import org.springframework.roo.addon.tostring.RooToString ;

    @RooJavaBean
    @RooToString
    @RooEntity
    public class UserPerson {

    private String name;

    }

    package com.example.domain;

    import org.springframework.roo.addon.entity.RooEntity;
    import org.springframework.roo.addon.javabean.RooJavaBean ;
    import org.springframework.roo.addon.tostring.RooToString ;

    @RooJavaBean
    @RooToString
    @RooEntity
    public class UserGroup {

    private UserPerson participant;

    }

    I believe I have a bug here. Would someone please confirm or show me the error of my ways. (I tried to attach the project as a tarball and was told by the uploader that its an invalid file.. :-/)

    TIA,
    Lorin

  • #2
    Works for me

    I tried to replicate your project using this script in Roo 1.1.4:

    Code:
    project --topLevelPackage com.example.groups
    persistence setup --database HYPERSONIC_IN_MEMORY --provider HIBERNATE 
    entity --class ~.domain.UserPerson
    field string --fieldName name
    entity --class ~.domain.UserGroup
    field reference --fieldName participant --type ~.domain.UserPerson
    controller all --package ~.web
    ... and it worked fine. Does the above script work for you, and if so, how does the generated project differ from yours?

    Comment


    • #3
      Andrew, thank you!

      Ok.. so yes, your script worked. I figured it was something I was doing wrong and it was. Sorry for using the "B" word.

      I was so focused on using Roo, I totally forgot my Hibernate. So the challenge that I was experiencing was this:

      I used:

      Code:
      field other --fieldName owner --type ~.domain.UserPerson
      as opposed to your:

      Code:
      field reference --fieldName participant --type ~.domain.UserPerson
      which, as I'm sure you know, resulted in code that was missing the ManyToOne annotation and that caused the error.

      Code:
      @RooJavaBean
      @RooToString
      @RooEntity
      public class UserGroup {
      
          @ManyToOne // <-- Was missing in my version.
          private UserPerson participant;
      }
      Hopefully my momentary stupidity will save someone else many hours. Thanks again.

      -Lorin

      Comment


      • #4
        It's all right, there was a lot worse "B" words you could have used! Glad it worked for you.

        Comment

        Working...
        X