Quantcast

Grails 1.2.0 DuplicateMappingException

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Grails 1.2.0 DuplicateMappingException

Stan Carney-4
So I have just tried to upgrade from 1.1.1 to 1.2.0 and I'm immediately
hit with a DuplicateMappingException. With 1.1.1 we have a few classes
mapped via .hbm.xml as they needed to use some of hibernates more
advanced configuration abilities.

It appears to be related to the fact that the domain class appears both
in grails-app/domain and has an associated MyClass.hbm.xml configured
via hibernate.cfg, a configuration that worked without issue in 1.1.1.
I've searched the web and this mailing list only to find a really old
pre-1.0 bug and mention of a similar sounding bug in Nimble that is now
closed.

Can anybody be of assistance?

Thanks,
Stan


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 1.2.0 DuplicateMappingException

burtbeckwith
If you're using hbm files, you don't want the source files to be in grails-app/domain since that's where the auto-mapped stuff goes. If it worked pre-1.2 it was something of a bug. Just move them to src/groovy.

Burt

> So I have just tried to upgrade from 1.1.1 to 1.2.0 and I'm immediately
> hit with a DuplicateMappingException. With 1.1.1 we have a few classes
> mapped via .hbm.xml as they needed to use some of hibernates more
> advanced configuration abilities.
>
> It appears to be related to the fact that the domain class appears both
> in grails-app/domain and has an associated MyClass.hbm.xml configured
> via hibernate.cfg, a configuration that worked without issue in 1.1.1.
> I've searched the web and this mailing list only to find a really old
> pre-1.0 bug and mention of a similar sounding bug in Nimble that is now
> closed.
>
> Can anybody be of assistance?
>
> Thanks,
> Stan

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 1.2.0 DuplicateMappingException

mlawler
I had a similar problem -> used to work fine in 1.1.1 and 1.2-M4 but now a DuplicateMappingException when I come to 1.2.0 (havent tried 1.2-RC1 or 1.2-RC2). I've taken your advice and moved my hbm-mapped domain objects to src/groovy, but now the auto-mapped GORM domain objects that reference them cant see them. Disclaimer: I am using maven/grails integration.

Two more questions for anyone with grails/maven/auto-map/hbm-map experience:

Q1. Can auto-mapped GORM domain objects have GORM relationships with hbm-mapped domain objects
Q2. Where should the <domain_object>hbm.xml files go? In grails-app/conf/hibernate or in src/java ?


Burt Beckwith wrote
If you're using hbm files, you don't want the source files to be in grails-app/domain since that's where the auto-mapped stuff goes. If it worked pre-1.2 it was something of a bug. Just move them to src/groovy.

Burt

> So I have just tried to upgrade from 1.1.1 to 1.2.0 and I'm immediately
> hit with a DuplicateMappingException. With 1.1.1 we have a few classes
> mapped via .hbm.xml as they needed to use some of hibernates more
> advanced configuration abilities.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 1.2.0 DuplicateMappingException

Stan Carney-4
In reply to this post by burtbeckwith
I see. So I have moved the affected domain classes over and I no longer
get those errors. Spring is failing to start with an ambiguous error now
(Error creating bean with name 'messageSource') but I'm not sure if it
is related. Need to investigate more.

Thanks for your help.

Stan


On 10-01-06 10:43 PM, Burt Beckwith wrote:

> If you're using hbm files, you don't want the source files to be in grails-app/domain since that's where the auto-mapped stuff goes. If it worked pre-1.2 it was something of a bug. Just move them to src/groovy.
>
> Burt
>
>> So I have just tried to upgrade from 1.1.1 to 1.2.0 and I'm immediately
>> hit with a DuplicateMappingException. With 1.1.1 we have a few classes
>> mapped via .hbm.xml as they needed to use some of hibernates more
>> advanced configuration abilities.
>>
>> It appears to be related to the fact that the domain class appears both
>> in grails-app/domain and has an associated MyClass.hbm.xml configured
>> via hibernate.cfg, a configuration that worked without issue in 1.1.1.
>> I've searched the web and this mailing list only to find a really old
>> pre-1.0 bug and mention of a similar sounding bug in Nimble that is now
>> closed.
>>
>> Can anybody be of assistance?
>>
>> Thanks,
>> Stan
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 1.2.0 DuplicateMappingException

Stan Carney-4
So it appears the NullPointerException I'm now getting might be related
to the DuplicateMappingException I was getting earlier.

I have tracked it back to this block of code in GrailsDomainBinder.java:459

GrailsDomainClassProperty otherSide = property.getOtherSide();
if (otherSide.isManyToOne() &&
shouldBindCollectionWithForeignKey(property)) {
                linkBidirectionalOneToMany(collection, associatedClass,
key, otherSide);
            } else if (property.isManyToMany() ||
Map.class.isAssignableFrom(property.getType())) {
                bindDependentKeyValue(property, key, mappings);
            }

We have a 'normal' grails domain class that has a many-to-one mapping to
one of our 'hbm.xml' classes. This class was moved to src/groovy in
order to avoid the DuplicateMappingException, which it did. The problem
with the above code is that otherSide is null.


Simplified example:

//regular grails domain class
class Shelf {

        Long id
        Long version

        Set books = []

        static constraints = {
                books(nullable: true)
        }

        static hasMany = [books: Book]

        static mapping = {
                columns {
                        books batchSize: 50
                        books lazy: true
                }
        }
}

 <class name="Book" table="book" optimistic-lock="version">
        <id name="id" type="long" column="id">
            <generator class="foreign">
                <param name="property">item</param>
            </generator>
        </id>

        <version type="long" name="version"/>

        <property name="name" column="name" type="string" not-null="true"/>

        <one-to-one name="item" class="Item" constrained="true"
fetch="join"/>
        <many-to-one name="shelf" class="Shelf" column="shelf_id"
                     fetch="select" not-null="false"/>
    </class>


When the above GrailsDomainBinder code tries to call
property.getOtherSide() when property is Shelf getOtherSide() returns null.

Thoughts?


Thanks,
Stan


On 10-01-07 8:26 PM, Stan Carney wrote:

> I see. So I have moved the affected domain classes over and I no longer
> get those errors. Spring is failing to start with an ambiguous error now
> (Error creating bean with name 'messageSource') but I'm not sure if it
> is related. Need to investigate more.
>
> Thanks for your help.
>
> Stan
>
>
> On 10-01-06 10:43 PM, Burt Beckwith wrote:
>> If you're using hbm files, you don't want the source files to be in grails-app/domain since that's where the auto-mapped stuff goes. If it worked pre-1.2 it was something of a bug. Just move them to src/groovy.
>>
>> Burt
>>
>>> So I have just tried to upgrade from 1.1.1 to 1.2.0 and I'm immediately
>>> hit with a DuplicateMappingException. With 1.1.1 we have a few classes
>>> mapped via .hbm.xml as they needed to use some of hibernates more
>>> advanced configuration abilities.
>>>
>>> It appears to be related to the fact that the domain class appears both
>>> in grails-app/domain and has an associated MyClass.hbm.xml configured
>>> via hibernate.cfg, a configuration that worked without issue in 1.1.1.
>>> I've searched the web and this mailing list only to find a really old
>>> pre-1.0 bug and mention of a similar sounding bug in Nimble that is now
>>> closed.
>>>
>>> Can anybody be of assistance?
>>>
>>> Thanks,
>>> Stan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 1.2.0 DuplicateMappingException

Stan Carney-4
I created the following bug ticket for the issue:
http://jira.codehaus.org/browse/GRAILS-5721

Stan


On 10-01-13 12:00 AM, Stan Carney wrote:

> So it appears the NullPointerException I'm now getting might be related
> to the DuplicateMappingException I was getting earlier.
>
> I have tracked it back to this block of code in GrailsDomainBinder.java:459
>
> GrailsDomainClassProperty otherSide = property.getOtherSide();
> if (otherSide.isManyToOne() &&
> shouldBindCollectionWithForeignKey(property)) {
>                 linkBidirectionalOneToMany(collection, associatedClass,
> key, otherSide);
>             } else if (property.isManyToMany() ||
> Map.class.isAssignableFrom(property.getType())) {
>                 bindDependentKeyValue(property, key, mappings);
>             }
>
> We have a 'normal' grails domain class that has a many-to-one mapping to
> one of our 'hbm.xml' classes. This class was moved to src/groovy in
> order to avoid the DuplicateMappingException, which it did. The problem
> with the above code is that otherSide is null.
>
>
> Simplified example:
>
> //regular grails domain class
> class Shelf {
>
> Long id
> Long version
>
> Set books = []
>
> static constraints = {
> books(nullable: true)
> }
>
> static hasMany = [books: Book]
>
> static mapping = {
> columns {
> books batchSize: 50
> books lazy: true
> }
> }
> }
>
>  <class name="Book" table="book" optimistic-lock="version">
>         <id name="id" type="long" column="id">
>             <generator class="foreign">
>                 <param name="property">item</param>
>             </generator>
>         </id>
>
>         <version type="long" name="version"/>
>
>         <property name="name" column="name" type="string" not-null="true"/>
>
>         <one-to-one name="item" class="Item" constrained="true"
> fetch="join"/>
>         <many-to-one name="shelf" class="Shelf" column="shelf_id"
>                      fetch="select" not-null="false"/>
>     </class>
>
>
> When the above GrailsDomainBinder code tries to call
> property.getOtherSide() when property is Shelf getOtherSide() returns null.
>
> Thoughts?
>
>
> Thanks,
> Stan
>
>
> On 10-01-07 8:26 PM, Stan Carney wrote:
>> I see. So I have moved the affected domain classes over and I no longer
>> get those errors. Spring is failing to start with an ambiguous error now
>> (Error creating bean with name 'messageSource') but I'm not sure if it
>> is related. Need to investigate more.
>>
>> Thanks for your help.
>>
>> Stan
>>
>>
>> On 10-01-06 10:43 PM, Burt Beckwith wrote:
>>> If you're using hbm files, you don't want the source files to be in grails-app/domain since that's where the auto-mapped stuff goes. If it worked pre-1.2 it was something of a bug. Just move them to src/groovy.
>>>
>>> Burt
>>>
>>>> So I have just tried to upgrade from 1.1.1 to 1.2.0 and I'm immediately
>>>> hit with a DuplicateMappingException. With 1.1.1 we have a few classes
>>>> mapped via .hbm.xml as they needed to use some of hibernates more
>>>> advanced configuration abilities.
>>>>
>>>> It appears to be related to the fact that the domain class appears both
>>>> in grails-app/domain and has an associated MyClass.hbm.xml configured
>>>> via hibernate.cfg, a configuration that worked without issue in 1.1.1.
>>>> I've searched the web and this mailing list only to find a really old
>>>> pre-1.0 bug and mention of a similar sounding bug in Nimble that is now
>>>> closed.
>>>>
>>>> Can anybody be of assistance?
>>>>
>>>> Thanks,
>>>> Stan
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>     http://xircles.codehaus.org/manage_email
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...