Announcement Announcement Module
Collapse
No announcement yet.
hbm - Duplicate Class Entity Mapping - Why!? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hbm - Duplicate Class Entity Mapping - Why!?

    Please help. This is driving me crazy at this point.

    I have a very simple class and corresponding hbm.xml file. I had it working this morning perfectly. I added a second hbm.xml file to the mix and everything stopped working. I removed the second hbm.xml and reverted back to the original and it now gives me a "Duplicate Class Entity/Mapping" message on the original hbm.xml.

    I'm using spring-security-core and spring-security-cas plugins although they seem to have been causing no issues. I am letting GORM handle the Role and User_Role entities and am using hbm for the User because I need to pull data from my legacy DB during authentication.

    I happened to look at my plugins directory and see a 'release 1.0.0.M2' entry that I did not install and is are not a part of any of my other projects. I can uninstall it but when I do a run-app it is redownloaded and installed.

    I ran clean and then a refresh Grails Dependencies but it did not help.

    I am running STS 2.7.1 RELEASE Build 201107091000. (The current Mac OSX dmg downloads that are out there on the STS download page appear to be corrupted). I mention this because I have been getting random 'Cannot resolve class E' error messages in the STS IDE ever since I download and installed STS tar.gz last week springsource-tool-suite-2.7.1.RELEASE-e3.7-macosx-carbon.tar.gz (I tried both the cocoa and carbon dmgs with no success, it opens disk utility instead of installing the app). My old STS install would have an eclipse-groovy update everyday and this one has none. I am wondering if there is an issue with the IDE itself.


    Contents of my /grails-app/conf/hibernate/hibernate.cfg.xml:
    Code:
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
    	'-//Hibernate/Hibernate Configuration DTD 3.0//EN'
    	'http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd'>
    	
    <hibernate-configuration>
    	<session-factory>
    		<mapping resource="Person.hbm.xml" />
    	</session-factory>
    </hibernate-configuration>
    Contents of the /grails-app/conf/hibernate/Person.hbm.xml:
    Code:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping>
    	<class name="edu.conncoll.banner.Person" table="CC_WRKCRD_PERSON_VW"
    					dynamic-insert="false" dynamic-update="false">
    
    		<id name="pidm" column="table_pidm" type="long"><generator class="assigned" /></id>
    
    		<property name="bannerId" column="table_id" />
    		<property name="thirdPartyId" column="table_external_user" />
    		<property name="lastName" column="table_last_name" />
    		<property name="firstName" column="table_first_name" />
    		<property name="middleInitial" column="table_mi" />
    		<property name="preferredName" column="vw_pref_first_name" />
    		<property name="email" column="table_email_address" />
    
    		<joined-subclass name="edu.conncoll.banner.User" table="CC_WRKCRD_USER_VW"
    						dynamic-insert="false" dynamic-update="false">
    			<key column="pidm" />
    
    			<property name="id" column="id" />
    			<property name="username" column="username" />
    			<property name="password" column="password" />
    			<property name="enabled" column="enabled" />
    			<property name="accountExpired" column="account_expired" />
    			<property name="accountLocked" column="account_locked" />
    			<property name="passwordExpired" column="password_expired" />
    	
    		</joined-subclass>
    
    	</class>
    
    </hibernate-mapping>
    Here is the /grails-app/domain/edu/conncoll/banner/Person class:
    Code:
    package edu.conncoll.banner
    
    import java.io.Serializable;
    
    class Person implements Serializable {
    
    	long   pidm
    	
    	String bannerId
    	String thirdPartyId
    	
    	String lastName
    	String firstName
    	String middleInitial
    	String preferredName
    	String email
    	
    	static constraints = {
    		bannerId		nullable: false, unique: true
    		pidm			nullable: false, unique: true
    		thirdPartyId	        nullable: true, unique: true
    		
    		lastName		nullable: false
    		firstName		nullable: false
    		middleInitial	nullable: true
    		preferredName	nullable: true		
    	}
    }
    Here is the /grails-app/domain/edu/conncoll/banner/User class:
    Code:
    package edu.conncoll.banner
    
    class User extends Person implements Serializable {
    
    	String username
    	String password
    	boolean enabled
    	boolean accountExpired
    	boolean accountLocked
    	boolean passwordExpired
    
    	static constraints = {
    		username blank: false, unique: true
    		password blank: false
    	}
    
    	Set<Role> getAuthorities() {
    		UserRole.findAllByUser(this).collect { it.role } as Set
    	}
    }
    Here is the stack trace:
    Code:
    Configuring Spring Security ...
    2011-08-02 11:21:07,161 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping edu.conncoll.banner.User
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping edu.conncoll.banner.User
    	at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:164)
    	at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    	at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
    	at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
    	at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
    	at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
    	at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
    	at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
    	at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
    	at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
    	at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
    	at RunApp$_run_closure1.doCall(RunApp.groovy:33)
    	at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    	at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    	at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    	at gant.Gant.withBuildListeners(Gant.groovy:427)
    	at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    	at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    	at gant.Gant.dispatch(Gant.groovy:415)
    	at gant.Gant.this$2$dispatch(Gant.groovy)
    	at gant.Gant.invokeMethod(Gant.groovy)
    	at gant.Gant.executeTargets(Gant.groovy:590)
    	at gant.Gant.executeTargets(Gant.groovy:589)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping edu.conncoll.banner.User
    	... 23 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping edu.conncoll.banner.User
    	... 23 more
    Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping edu.conncoll.banner.User
    	... 23 more
    Last edited by Brian Riley; Aug 2nd, 2011, 10:46 AM.

  • #2
    I tried moving the User.groovy and Person.groovy files from grails-app/domain to src/groovy per some suggestions I found online that date from 2010 and it looks like Grails can not find them. http://grails.1312388.n4.nabble.com/...td1392915.html In the forum post others had the same new NullPointer issue after moving their classes to src/groovy and it looks like it was fixed if I follow it through to the JIRA but I'm still the issue.

    Where should the hibernate hbm files go, and where should my groovy class files that they relate to go?

    Code:
    2011-08-02 14:26:12,857 [main] ERROR pojo.BasicLazyInitializer  - Javassist Enhancement failed: edu.conncoll.banner.User
    java.lang.RuntimeException: duplicate method: getId in edu.conncoll.banner.User_$$_javassist_0
    	at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:344)
    	at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:314)
    	at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:273)
    	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:162)
    	at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.postInstantiate(JavassistProxyFactory.java:66)
    	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:183)
    	at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:158)
    	at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:76)
    	at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
    	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:325)
    	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457)
    	at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:113)
    	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:87)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    	at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.buildSessionFactory(GrailsAnnotationConfiguration.java:109)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855)
    	at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.newSessionFactory(ConfigurableLocalSessionFactoryBean.java:126)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774)
    	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    	at ...
    	... 483 more
    2011-08-02 14:26:13,764 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    	at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:164)
    	at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    	at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
    	at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
    	at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
    	at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
    	at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
    	at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
    	at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
    	at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
    	at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
    	at RunApp$_run_closure1.doCall(RunApp.groovy:33)
    	at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    	at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    	at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    	at gant.Gant.withBuildListeners(Gant.groovy:427)
    	at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    	at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    	at gant.Gant.dispatch(Gant.groovy:415)
    	at gant.Gant.this$2$dispatch(Gant.groovy)
    	at gant.Gant.invokeMethod(Gant.groovy)
    	at gant.Gant.executeTargets(Gant.groovy:590)
    	at gant.Gant.executeTargets(Gant.groovy:589)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    	... 23 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    	... 23 more
    Caused by: java.lang.NullPointerException
    	... 23 more

    Comment


    • #3
      Which version of Grails are you using?

      Comment


      • #4
        Using Grails version 1.3.4

        Comment


        • #5
          OK. Just wanted to make sure this wasn't 2.0.0.M1. So, I recommend the following:

          1. Add the line 'grails.project.work.dir = "target"' to your project's BuildConfig.groovy file
          2. Delete your project's 'target' directory
          3. Make sure your Hibernate files are in grails-app/conf/hibernate
          4. Make sure your domain classes are in src/groovy
          5. grails compile
          6. grails run-app

          Let me know how that goes.

          Comment


          • #6
            I will have to revert back to an older copy of the project and give your suggestions a try.

            I moved all of my domain classes over to src/groovy and created hbm.xml files for them. Everything seems to be working now although I had to modify the User and Role objects created by spring-security-core to get them to work nicely.

            I also found that switching my:
            Code:
            static hasMany = [objects: object]
            over to:
            Code:
            Set objects
            was necessary in order for it to work with the hbm (perhaps I am just setting up the relationship incorrectly in hbm though).

            I am curious to see if the standard groovy constraints still work now that everything is in src/groovy.

            Comment


            • #7
              You're mixing up GORM and normal Java/Groovy domain classes. Things like 'static hasMany' and 'static constraints' are only processed if the domain class is in 'grails-app/domain'. By putting them in 'src/groovy' you have to manually add things, such as collection properties, that GORM normally does for you.

              As for the constraints, these need to be copied into 'src/java/path/to/domainClass/DomainClassConstraints.groovy', as described in my blog post about this.

              Hope that helps,

              Peter

              Comment


              • #8
                Thanks Peter!

                Comment

                Working...
                X