facebook

Illegal use of mappedBy on both sides of the relationship:

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #311231 Reply

    hi,

    I’m using

    myeclipse for spring

    to generate a JPA, Spring, GWT scaffolding code for a project. I’m using the wizard to auto generate from a mysql db and after compiling the project and running it on the built in instance of tomcat I get the following error……..any help would be greatly appreciated….thanks in advance

    2010-09-09 21:55:47,703 ERROR [main] ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AddressDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MySQL' defined in class path resource [myproject-generated-dao-context.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Illegal use of mappedBy on both sides of the relationship: com.myproject.domain.User.usersForUserId
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:341)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
        at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MySQL' defined in class path resource [myproject-generated-dao-context.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Illegal use of mappedBy on both sides of the relationship: com.myproject.domain.User.usersForUserId
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1403)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
        at org.springframework.orm.jpa.EntityManagerFactoryUtils.findEntityManagerFactory(EntityManagerFactoryUtils.java:99)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findNamedEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:510)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:492)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
        at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
        ... 37 more
    Caused by: org.hibernate.AnnotationException: Illegal use of mappedBy on both sides of the relationship: com.myproject.domain.User.usersForUserId
        at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:196)
        at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1322)
        at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1161)
        at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:600)
        at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:541)
        at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1149)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1134)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1225)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:159)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)

    please let me know any classes that you might need to see to help with this

    In my Address.java class

    /**
         */
        @ManyToOne( fetch = FetchType.LAZY)
        @JoinColumns( { @JoinColumn(name = "user_id", referencedColumnName = "user_id") })
        @XmlTransient
        User user;
        /**
         */

    this is my User.java class

        @OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
        @XmlElement(name = "", namespace = "")
        java.util.Set<com.myproject.domain.Address> addresses;
        /**
         */

    I tried adding targetEntity…but it had no affect

        /**
         */
        @OneToMany(targetEntity = com.myproject.domain.Address.class, mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
        @XmlElement(name = "", namespace = "")
        java.util.Set<com.myproject.domain.Address> addresses;
        /**
         */
    
    
        /**
         */
        @ManyToOne(targetEntity = com.myproject.domain.User.class, fetch = FetchType.LAZY)
        @JoinColumns( { @JoinColumn(name = "user_id", referencedColumnName = "user_id") })
        @XmlTransient
        User user;
        /**
         */

    thanks again

    pa

    #311243 Reply

    davemeurer
    Member

    Hello,

    This is a hibernate error due to an annotation in an attribute in User called “usersForUserId”. Is that an attribute on your User object? If so, please post the code around that attribute. Also, please post the schema for User. Do you know what type of relationship this attribute is supposed to have? (e.g. Many to Many, One to Many, etc)

    Kind regards,
    Dave

    #311278 Reply

    fbrody
    Member

    Thanks Dave,

    Your response, pointed me in the right direction

    f

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Illegal use of mappedBy on both sides of the relationship:

You must be logged in to post in the forum log in