Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » teneo: Yet another DuplicateMappingException problem
teneo: Yet another DuplicateMappingException problem [message #69718] Wed, 31 January 2007 21:42 Go to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I too am having a problem with a Duplicate<appingException being thrown. I have added the QUALIFY_ENTITY_NAME property with the value QUALIFY_ENTITY_NAME_NSPREFIX and still get the duplicate mapping exception. The complete exception trace is:

Exception in thread "main" org.hibernate.DuplicateMappingException: duplicate import: InterfaceCard refers to both cisco3800.InterfaceCard and types.InterfaceCard (try using auto-import="false")
at org.hibernate.cfg.Mappings.addImport(Mappings.java:141)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues( HbmBinder.java:614)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:527)
at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.jav a:848)
at org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.j ava:2202)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:424)
at org.hibernate.cfg.Configuration.addXML(Configuration.java:38 4)
at org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:364)
at org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
at org.ziptie.cisco.cs3800Load.doLoadDoc(cs3800Load.java:63)

There are two XSDs (one included by the other) with different namespaces, each with a type definition for InterfaceCard. The including XSD extends the type of the included namespace. When I look at the mapping, the entity-name fields are unique (they have the namespaces prefixed) and the descriminator fields are unique (again, the namespace is prefixed). In fact, everything is unique with the exception of the meta tag for "eclassName" - they are both InterfaceCard without any namespace prefixes.

I tried both the default and the "JOINED" Inheritance mapping strategies and both result in the same exception although the mappings are obviously a bit different. Here is the mapping for these types using the default inheritance strategy:

<subclass entity-name="types.InterfaceCard" abstract="false" lazy="false" extends="types.Card" discriminator-value="types.InterfaceCard">
<meta attribute="eclassName">InterfaceCard</meta>
<meta attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
<list name="port" lazy="true" cascade="all,delete-orphan">
<key update="true">
<column name="`interfacecard_port_id`" not-null="false" unique="false"/>
</key>
<list-index column="`interfacecard_port_idx`"/>
<one-to-many entity-name="types.Port"/>
</list>
</subclass>
<subclass entity-name="cisco3800.InterfaceCard" abstract="false" lazy="false" extends="types.InterfaceCard" discriminator-value="cisco3800.InterfaceCard">
<meta attribute="eclassName">InterfaceCard</meta>
<meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
<property name="icType" lazy="false" not-null="false" insert="true" update="true" unique="false">
<column not-null="false" unique="false" name="`ictype`"/>
<type name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
<param name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
</type>
</property>
</subclass>

And here is the mapping for the JOINED strategy:

<joined-subclass entity-name="types.InterfaceCard" abstract="false" lazy="false" extends="types.Card" table="`interfacecard`">
<meta attribute="eclassName">InterfaceCard</meta>
<meta attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
<key>
<column name="`card_id`"/>
</key>
<list name="port" lazy="true" cascade="all,delete-orphan">
<key update="true">
<column name="`interfacecard_port_id`" not-null="false" unique="false"/>
</key>
<list-index column="`interfacecard_port_idx`"/>
<one-to-many entity-name="types.Port"/>
</list>
</joined-subclass>
<joined-subclass entity-name="cisco3800.InterfaceCard" abstract="false" lazy="false" extends="types.InterfaceCard" table="`interfacecard`">
<meta attribute="eclassName">InterfaceCard</meta>
<meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
<key>
<column name="`interfacecard_id`"/>
</key>
<property name="icType" lazy="false" not-null="false" insert="true" update="true" unique="false">
<column not-null="false" unique="false" name="`ictype`"/>
<type name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
<param name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
</type>
</property>
</joined-subclass>

Like the default inheritance strategy, the entity-names are unique and the meta attribute eclassName is not. However, note that the table names are the same. That is probably bad mojo.

Outside of hand editing the generated hbm file, is there some other way to fix or control this behavior?

Thanks,

Brian
Re: teneo: Yet another DuplicateMappingException problem [message #69741 is a reply to message #69718] Wed, 31 January 2007 21:59 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I looked in the hibernate source and it seems that auto-import="false" can get rid of this error.
For now this has to be done manually, in the top-tag in the hbm.xml set the attribute
auto-import="false":
<hibernate-mapping
schema="schemaName" (1)
default-cascade="none|save-update" (2)
auto-import="true|false" (3)
package="package.name" (4)
/>

Let me know if this works then I'll add this as an option in Teneo.

gr. Martin

Brian Vetter wrote:
> I too am having a problem with a Duplicate<appingException being thrown.
> I have added the QUALIFY_ENTITY_NAME property with the value
> QUALIFY_ENTITY_NAME_NSPREFIX and still get the duplicate mapping
> exception. The complete exception trace is:
>
> Exception in thread "main" org.hibernate.DuplicateMappingException:
> duplicate import: InterfaceCard refers to both cisco3800.InterfaceCard
> and types.InterfaceCard (try using auto-import="false")
> at org.hibernate.cfg.Mappings.addImport(Mappings.java:141)
> at
> org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues( HbmBinder.java:614)
>
> at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:527)
> at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.jav a:848)
> at
> org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.j ava:2202)
> at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
> at org.hibernate.cfg.Configuration.add(Configuration.java:424)
> at org.hibernate.cfg.Configuration.addXML(Configuration.java:38 4)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:364)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
>
> at org.ziptie.cisco.cs3800Load.doLoadDoc(cs3800Load.java:63)
>
> There are two XSDs (one included by the other) with different
> namespaces, each with a type definition for InterfaceCard. The including
> XSD extends the type of the included namespace. When I look at the
> mapping, the entity-name fields are unique (they have the namespaces
> prefixed) and the descriminator fields are unique (again, the namespace
> is prefixed). In fact, everything is unique with the exception of the
> meta tag for "eclassName" - they are both InterfaceCard without any
> namespace prefixes.
>
> I tried both the default and the "JOINED" Inheritance mapping strategies
> and both result in the same exception although the mappings are
> obviously a bit different. Here is the mapping for these types using the
> default inheritance strategy:
>
> <subclass entity-name="types.InterfaceCard" abstract="false"
> lazy="false" extends="types.Card"
> discriminator-value="types.InterfaceCard">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta
> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
> <list name="port" lazy="true" cascade="all,delete-orphan">
> <key update="true">
> <column name="`interfacecard_port_id`" not-null="false"
> unique="false"/>
> </key>
> <list-index column="`interfacecard_port_idx`"/>
> <one-to-many entity-name="types.Port"/>
> </list>
> </subclass>
> <subclass entity-name="cisco3800.InterfaceCard" abstract="false"
> lazy="false" extends="types.InterfaceCard"
> discriminator-value="cisco3800.InterfaceCard">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
> <property name="icType" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`ictype`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
> <param
> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
> </type>
> </property>
> </subclass>
>
> And here is the mapping for the JOINED strategy:
>
> <joined-subclass entity-name="types.InterfaceCard" abstract="false"
> lazy="false" extends="types.Card" table="`interfacecard`">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta
> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
> <key>
> <column name="`card_id`"/>
> </key>
> <list name="port" lazy="true" cascade="all,delete-orphan">
> <key update="true">
> <column name="`interfacecard_port_id`" not-null="false"
> unique="false"/>
> </key>
> <list-index column="`interfacecard_port_idx`"/>
> <one-to-many entity-name="types.Port"/>
> </list>
> </joined-subclass>
> <joined-subclass entity-name="cisco3800.InterfaceCard"
> abstract="false" lazy="false" extends="types.InterfaceCard"
> table="`interfacecard`">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
> <key>
> <column name="`interfacecard_id`"/>
> </key>
> <property name="icType" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`ictype`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
> <param
> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
> </type>
> </property>
> </joined-subclass>
>
> Like the default inheritance strategy, the entity-names are unique and
> the meta attribute eclassName is not. However, note that the table names
> are the same. That is probably bad mojo.
>
> Outside of hand editing the generated hbm file, is there some other way
> to fix or control this behavior?
>
> Thanks,
>
> Brian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: teneo: Yet another DuplicateMappingException problem [message #69761 is a reply to message #69741] Wed, 31 January 2007 23:13 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I changed to use the statically built hbm.xml file and set auto-import to false. Hibernate was able to load the mapping file and create the tables. So if you can let us set auto-import to false as a persistence option or automatically set it for cases when QUALIFY_ENTITY_NAME is set to use the namespace prefix, that would be cool.

I still have one problem. When I use the JOINED inheritance strategy, it specifies the same table name for the two types. The latter definition overrides the former and I only get a single table.

Brian

Martin Taal wrote:
> I looked in the hibernate source and it seems that auto-import="false"
> can get rid of this error.
> For now this has to be done manually, in the top-tag in the hbm.xml set
> the attribute auto-import="false":
> <hibernate-mapping
> schema="schemaName" (1)
> default-cascade="none|save-update" (2)
> auto-import="true|false" (3)
> package="package.name" (4)
> />
>
> Let me know if this works then I'll add this as an option in Teneo.
>
> gr. Martin
>
> Brian Vetter wrote:
>> I too am having a problem with a Duplicate<appingException being
>> thrown. I have added the QUALIFY_ENTITY_NAME property with the value
>> QUALIFY_ENTITY_NAME_NSPREFIX and still get the duplicate mapping
>> exception. The complete exception trace is:
>>
>> Exception in thread "main" org.hibernate.DuplicateMappingException:
>> duplicate import: InterfaceCard refers to both cisco3800.InterfaceCard
>> and types.InterfaceCard (try using auto-import="false")
>> at org.hibernate.cfg.Mappings.addImport(Mappings.java:141)
>> at
>> org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues( HbmBinder.java:614)
>>
>> at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:527)
>> at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.jav a:848)
>> at
>> org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.j ava:2202)
>> at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
>> at org.hibernate.cfg.Configuration.add(Configuration.java:424)
>> at org.hibernate.cfg.Configuration.addXML(Configuration.java:38 4)
>> at
>> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:364)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
>>
>> at org.ziptie.cisco.cs3800Load.doLoadDoc(cs3800Load.java:63)
>>
>> There are two XSDs (one included by the other) with different
>> namespaces, each with a type definition for InterfaceCard. The
>> including XSD extends the type of the included namespace. When I look
>> at the mapping, the entity-name fields are unique (they have the
>> namespaces prefixed) and the descriminator fields are unique (again,
>> the namespace is prefixed). In fact, everything is unique with the
>> exception of the meta tag for "eclassName" - they are both
>> InterfaceCard without any namespace prefixes.
>>
>> I tried both the default and the "JOINED" Inheritance mapping
>> strategies and both result in the same exception although the mappings
>> are obviously a bit different. Here is the mapping for these types
>> using the default inheritance strategy:
>>
>> <subclass entity-name="types.InterfaceCard" abstract="false"
>> lazy="false" extends="types.Card"
>> discriminator-value="types.InterfaceCard">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta
>> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
>> <list name="port" lazy="true" cascade="all,delete-orphan">
>> <key update="true">
>> <column name="`interfacecard_port_id`"
>> not-null="false" unique="false"/>
>> </key>
>> <list-index column="`interfacecard_port_idx`"/>
>> <one-to-many entity-name="types.Port"/>
>> </list>
>> </subclass>
>> <subclass entity-name="cisco3800.InterfaceCard" abstract="false"
>> lazy="false" extends="types.InterfaceCard"
>> discriminator-value="cisco3800.InterfaceCard">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
>> <property name="icType" lazy="false" not-null="false"
>> insert="true" update="true" unique="false">
>> <column not-null="false" unique="false" name="`ictype`"/>
>> <type
>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>> <param
>> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
>> </type>
>> </property>
>> </subclass>
>>
>> And here is the mapping for the JOINED strategy:
>>
>> <joined-subclass entity-name="types.InterfaceCard"
>> abstract="false" lazy="false" extends="types.Card"
>> table="`interfacecard`">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta
>> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
>> <key>
>> <column name="`card_id`"/>
>> </key>
>> <list name="port" lazy="true" cascade="all,delete-orphan">
>> <key update="true">
>> <column name="`interfacecard_port_id`"
>> not-null="false" unique="false"/>
>> </key>
>> <list-index column="`interfacecard_port_idx`"/>
>> <one-to-many entity-name="types.Port"/>
>> </list>
>> </joined-subclass>
>> <joined-subclass entity-name="cisco3800.InterfaceCard"
>> abstract="false" lazy="false" extends="types.InterfaceCard"
>> table="`interfacecard`">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
>> <key>
>> <column name="`interfacecard_id`"/>
>> </key>
>> <property name="icType" lazy="false" not-null="false"
>> insert="true" update="true" unique="false">
>> <column not-null="false" unique="false" name="`ictype`"/>
>> <type
>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>> <param
>> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
>> </type>
>> </property>
>> </joined-subclass>
>>
>> Like the default inheritance strategy, the entity-names are unique and
>> the meta attribute eclassName is not. However, note that the table
>> names are the same. That is probably bad mojo.
>>
>> Outside of hand editing the generated hbm file, is there some other
>> way to fix or control this behavior?
>>
>> Thanks,
>>
>> Brian
>
>
Re: teneo: Yet another DuplicateMappingException problem [message #69780 is a reply to message #69761] Thu, 01 February 2007 00:44 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
BTW, I'd like the behavior to be that the name of the tables were prefixed with the namespace prefix. If this isn't the default, I'd like to have a way to control/force it.

Thanks,

Brian

Brian Vetter wrote:
> I changed to use the statically built hbm.xml file and set auto-import
> to false. Hibernate was able to load the mapping file and create the
> tables. So if you can let us set auto-import to false as a persistence
> option or automatically set it for cases when QUALIFY_ENTITY_NAME is set
> to use the namespace prefix, that would be cool.
>
> I still have one problem. When I use the JOINED inheritance strategy, it
> specifies the same table name for the two types. The latter definition
> overrides the former and I only get a single table.
>
> Brian
>
Re: teneo: Yet another DuplicateMappingException problem [message #69801 is a reply to message #69780] Thu, 01 February 2007 05:49 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I'll change the following:
set auto-import to false when qualify-entity names is set to nsprefix
include nsprefix in the default table name in case of qualify entity name

In the meantime you can use a table annotation on the eclass to set a different table name.

Btw, the meta eclass tag is not unique because it also has an accompanying epackage tag.

gr. Martin

Brian Vetter wrote:
> BTW, I'd like the behavior to be that the name of the tables were
> prefixed with the namespace prefix. If this isn't the default, I'd like
> to have a way to control/force it.
>
> Thanks,
>
> Brian
>
> Brian Vetter wrote:
>> I changed to use the statically built hbm.xml file and set auto-import
>> to false. Hibernate was able to load the mapping file and create the
>> tables. So if you can let us set auto-import to false as a persistence
>> option or automatically set it for cases when QUALIFY_ENTITY_NAME is
>> set to use the namespace prefix, that would be cool.
>>
>> I still have one problem. When I use the JOINED inheritance strategy,
>> it specifies the same table name for the two types. The latter
>> definition overrides the former and I only get a single table.
>>
>> Brian
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Teneo: Persistence Mapping XML files for multiple namespaces; was: Yet another DuplicateMappingExcep [message #69840 is a reply to message #69801] Thu, 01 February 2007 17:55 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I'd like to maintain the persistence mappings outside of the original XSD files if possible. I believe I can do this using the PERSISTENCE_XML option to provide a resource file. However, I have some questions on how this will work if there are multiple XSDs with multiple namespaces. Here are the scenarios:

- Each "resource" type has its own XSD and namespace.
- There are several namespaces that are common to all of the resource types. These common namespaces and their type/element definitions are imported into each of the resource type XSDs.
- Resource types can be added dynamically to a system (through either importing new Jars or perhaps in the future, the use of dynamic APIs).
- Each resource type may have their own persistence mapping strategies for the types they introduce.
- Two separate installations/deployments may want to use the core XSDs for resource typing, but may want to have different persistence strategies.

Because of this last point, we want to keep the persistence mapping directives out of the core XSDs and potentially replace the mapping strategies for each of the resource XSDs. Sharing of the XSDs is important. Sharing the persistence mappings is less important and perhaps not possible.

In looking through the example persistence mapping file examples, it wasn't clear to me first if it was possible to have multiple active mapping files. Second, it wasn't clear to me how it would deal with multiple namespaces, especially when the base type names may be the same for two types in different namespaces.

Also, it appears that the separate XML examples are using the mapped ecore types although the modeling dudes here are using XSDs.

Am I missing something important? Any suggestions on how I might best organize the mapping files and the XSDs?

Thanks,

Brian


Martin Taal wrote:
>
> In the meantime you can use a table annotation on the eclass to set a
> different table name.
>
Re: Teneo: Persistence Mapping XML files for multiple namespaces; was: Yet another DuplicateMappingE [message #69861 is a reply to message #69840] Thu, 01 February 2007 20:00 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Brian,
Yes keeping the annotations outside of the xsd is a good approach. It keeps your model clean.

Currently you can only specify one xml file with additional mapping directives. Please enter a
bugzilla if you require support for multiple xml annotation files.

The xml annotation file can contain multiple epackages so this should work fine (see the xsd) for
your case (having eclasses with the same name).

Regarding the mapped ecore type use in the annotation xml. There is no other way but normally you
should be able to easily determine the eclass/efeature name from the xsd element definitions (the
names should be the same).

Btw, the build of today should solve your auto-import and tablename issue.

gr. Martin

Brian Vetter wrote:
> I'd like to maintain the persistence mappings outside of the original
> XSD files if possible. I believe I can do this using the PERSISTENCE_XML
> option to provide a resource file. However, I have some questions on
> how this will work if there are multiple XSDs with multiple namespaces.
> Here are the scenarios:
>
> - Each "resource" type has its own XSD and namespace.
> - There are several namespaces that are common to all of the resource
> types. These common namespaces and their type/element definitions are
> imported into each of the resource type XSDs.
> - Resource types can be added dynamically to a system (through either
> importing new Jars or perhaps in the future, the use of dynamic APIs).
> - Each resource type may have their own persistence mapping strategies
> for the types they introduce.
> - Two separate installations/deployments may want to use the core XSDs
> for resource typing, but may want to have different persistence strategies.
>
> Because of this last point, we want to keep the persistence mapping
> directives out of the core XSDs and potentially replace the mapping
> strategies for each of the resource XSDs. Sharing of the XSDs is
> important. Sharing the persistence mappings is less important and
> perhaps not possible.
>
> In looking through the example persistence mapping file examples, it
> wasn't clear to me first if it was possible to have multiple active
> mapping files. Second, it wasn't clear to me how it would deal with
> multiple namespaces, especially when the base type names may be the same
> for two types in different namespaces.
>
> Also, it appears that the separate XML examples are using the mapped
> ecore types although the modeling dudes here are using XSDs.
>
> Am I missing something important? Any suggestions on how I might best
> organize the mapping files and the XSDs?
>
> Thanks,
>
> Brian
>
>
> Martin Taal wrote:
>>
>> In the meantime you can use a table annotation on the eclass to set a
>> different table name.
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: teneo: Yet another DuplicateMappingException problem [message #70125 is a reply to message #69801] Fri, 02 February 2007 14:30 Go to previous messageGo to next message
JG is currently offline JGFriend
Messages: 51
Registered: July 2009
Member
Martin Taal wrote:
> I'll change the following:
> set auto-import to false when qualify-entity names is set to nsprefix
> include nsprefix in the default table name in case of qualify entity name
>
> In the meantime you can use a table annotation on the eclass to set a
> different table name.
>
> Btw, the meta eclass tag is not unique because it also has an
> accompanying epackage tag.
>


And from one of Brian's messages:


Brian Vetter wrote:

> In looking through the example persistence mapping file examples, it
> wasn't clear to me first if it was possible to have multiple active
> mapping files. Second, it wasn't clear to me how it would deal with
> multiple namespaces, especially when the base type names may be the same
> for two types in different namespaces.




I believe I stumbled across exactly this problem. I have two classes
named "Attribute" intwo different packages. When I simply use Teneo's
default mapping, I get this error:



[INFO ] duplicate import: Attribute->Attribute
[INFO ] Mapping subclass: Attribute -> instance
Exception in thread "main" org.hibernate.DuplicateMappingException:
Duplicate class/entity mapping Attribute
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 12)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addXML(Configuration.java:44 0)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
at paladin.TeneoTest.main(TeneoTest.java:51)


So I figured that Teneo does not qualify the table names, and looked for
a way to influence the mapping. I did this:

<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo">
<epackage namespace-uri="http:///p/m/xml.ecore">
<eclass name="Attribute">
<table name="XMLAttribute"/>
</eclass>
</epackage>
</persistence-mapping>


I set the PERSISTENCE_XML property accordingly and got this one:

DEBUG] located
[http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
[ERROR] Error parsing XML: XML String(1253) Attribute "table" must be
declared for element type "subclass".
Exception in thread "main" org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addXML(Configuration.java:43 8)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
at paladin.TeneoTest.main(TeneoTest.java:51)
Caused by: org.xml.sax.SAXParseException: Attribute "table" must be
declared for element type "subclass".


So I looked at the mapping file that was generated... of all subclass
elements, only ONE actually had a table attribute, the one for my
Attribute that I wanted to rename. All others didn't. So i looked at the
Hibernate-Mapping DTD and was surprised to see that subclass elements
are not even supposed to have table elements.

What am I missing here? Am I using the wrong way to rename the table for
conflicting entities?

I actually would prefer manual conflict resolution instead of having the
table names be qualified (I understand that this is the solution you
have been working on).

Regards

Jürgen
Re: teneo: Yet another DuplicateMappingException problem [message #70142 is a reply to message #70125] Fri, 02 February 2007 14:48 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
In case of the same eclass name occuring in different epackages then you need to set the
PersistenceOptions.QUALIFY_ENTITY_NAME option to PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX.
This will also qualify the table name for all eclasses (added in the release yesterday).
What I understand is that you use a single table inheritance mapping. In this case the table
annotation does not work for a subclass as a subclass is stored in the same table as its superclass.
The table annotation is usefull for joined-subclass inheritance mapping and in case of single-table
for the roots of the inheritance hierarchy.

Teneo should not add a table attribute to a subclass tag (maybe report a warning if a table
annotation is found). Can you enter a bugzilla for that?

gr. Martin

JG wrote:
> Martin Taal wrote:
>> I'll change the following:
>> set auto-import to false when qualify-entity names is set to nsprefix
>> include nsprefix in the default table name in case of qualify entity name
>>
>> In the meantime you can use a table annotation on the eclass to set a
>> different table name.
>>
>> Btw, the meta eclass tag is not unique because it also has an
>> accompanying epackage tag.
>>
>
>
> And from one of Brian's messages:
>
>
> Brian Vetter wrote:
>
>> In looking through the example persistence mapping file examples, it
>> wasn't clear to me first if it was possible to have multiple active
>> mapping files. Second, it wasn't clear to me how it would deal with
>> multiple namespaces, especially when the base type names may be the same
>> for two types in different namespaces.
>
>
>
>
> I believe I stumbled across exactly this problem. I have two classes
> named "Attribute" intwo different packages. When I simply use Teneo's
> default mapping, I get this error:
>
>
>
> [INFO ] duplicate import: Attribute->Attribute
> [INFO ] Mapping subclass: Attribute -> instance
> Exception in thread "main" org.hibernate.DuplicateMappingException:
> Duplicate class/entity mapping Attribute
> at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 12)
> at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
> at org.hibernate.cfg.Configuration.add(Configuration.java:669)
> at org.hibernate.cfg.Configuration.addXML(Configuration.java:44 0)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
> at paladin.TeneoTest.main(TeneoTest.java:51)
>
>
> So I figured that Teneo does not qualify the table names, and looked for
> a way to influence the mapping. I did this:
>
> <persistence-mapping xmlns="http://www.eclipse.org/emft/teneo">
> <epackage namespace-uri="http:///p/m/xml.ecore">
> <eclass name="Attribute">
> <table name="XMLAttribute"/>
> </eclass>
> </epackage>
> </persistence-mapping>
>
>
> I set the PERSISTENCE_XML property accordingly and got this one:
>
> DEBUG] located
> [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
> [ERROR] Error parsing XML: XML String(1253) Attribute "table" must be
> declared for element type "subclass".
> Exception in thread "main" org.hibernate.MappingException: invalid mapping
> at org.hibernate.cfg.Configuration.addXML(Configuration.java:43 8)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
> at paladin.TeneoTest.main(TeneoTest.java:51)
> Caused by: org.xml.sax.SAXParseException: Attribute "table" must be
> declared for element type "subclass".
>
>
> So I looked at the mapping file that was generated... of all subclass
> elements, only ONE actually had a table attribute, the one for my
> Attribute that I wanted to rename. All others didn't. So i looked at the
> Hibernate-Mapping DTD and was surprised to see that subclass elements
> are not even supposed to have table elements.
>
> What am I missing here? Am I using the wrong way to rename the table for
> conflicting entities?
>
> I actually would prefer manual conflict resolution instead of having the
> table names be qualified (I understand that this is the solution you
> have been working on).
>
> Regards
>
> Jürgen
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Another issue: hibernate.cfg.xml ignored? (was: Re: teneo: Yet another DuplicateMappingException pro [message #70162 is a reply to message #70142] Fri, 02 February 2007 15:29 Go to previous messageGo to next message
JG is currently offline JGFriend
Messages: 51
Registered: July 2009
Member
Martin Taal wrote:
> In case of the same eclass name occuring in different epackages then you
> need to set the PersistenceOptions.QUALIFY_ENTITY_NAME option to
> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX. This will also qualify
> the table name for all eclasses (added in the release yesterday).

> What I understand is that you use a single table inheritance mapping. In
> this case the table annotation does not work for a subclass as a
> subclass is stored in the same table as its superclass.

Funny thing is, some thought like that had already crossed my mind
("Hey, there's only one table, how should that work."), but I thought
that it was a conflict with the type tag in the single table, and that
setting the table override would do the trick.

> The table annotation is usefull for joined-subclass inheritance mapping
> and in case of single-table for the roots of the inheritance hierarchy.

>
> Teneo should not add a table attribute to a subclass tag (maybe report a
> warning if a table annotation is found). Can you enter a bugzilla for that?

Done. :-)


I got another issue: I placed a hibernate.cfg.xml into the root of my
EMF model package structure, in order to configure Hibernate.
Apparently, this file is ignored. Do I have to set hibernate properties
programmatically?


Regards

Jürgen
Re: Another issue: hibernate.cfg.xml ignored? [message #70182 is a reply to message #70162] Fri, 02 February 2007 15:59 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hmm the hibernate.cfg.xml should work afaics (I would need to look in more detail to see why this
would not work). You can also pass all the hibernate configuration properties programmatically using
the setHibernateProperties on the HbDataStore or place a hibernate.properties file in the root of
the classpath. See here:
http://www.elver.org/hibernate/tutorialone/tutorial1_2.html

gr. Martin

JG wrote:
> Martin Taal wrote:
>> In case of the same eclass name occuring in different epackages then you
>> need to set the PersistenceOptions.QUALIFY_ENTITY_NAME option to
>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX. This will also qualify
>> the table name for all eclasses (added in the release yesterday).
>
>> What I understand is that you use a single table inheritance mapping. In
>> this case the table annotation does not work for a subclass as a
>> subclass is stored in the same table as its superclass.
>
> Funny thing is, some thought like that had already crossed my mind
> ("Hey, there's only one table, how should that work."), but I thought
> that it was a conflict with the type tag in the single table, and that
> setting the table override would do the trick.
>
>> The table annotation is usefull for joined-subclass inheritance mapping
>> and in case of single-table for the roots of the inheritance hierarchy.
>
>> Teneo should not add a table attribute to a subclass tag (maybe report a
>> warning if a table annotation is found). Can you enter a bugzilla for that?
>
> Done. :-)
>
>
> I got another issue: I placed a hibernate.cfg.xml into the root of my
> EMF model package structure, in order to configure Hibernate.
> Apparently, this file is ignored. Do I have to set hibernate properties
> programmatically?
>
>
> Regards
>
> Jürgen


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: teneo: Yet another DuplicateMappingException problem [message #601887 is a reply to message #69718] Wed, 31 January 2007 21:59 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I looked in the hibernate source and it seems that auto-import="false" can get rid of this error.
For now this has to be done manually, in the top-tag in the hbm.xml set the attribute
auto-import="false":
<hibernate-mapping
schema="schemaName" (1)
default-cascade="none|save-update" (2)
auto-import="true|false" (3)
package="package.name" (4)
/>

Let me know if this works then I'll add this as an option in Teneo.

gr. Martin

Brian Vetter wrote:
> I too am having a problem with a Duplicate<appingException being thrown.
> I have added the QUALIFY_ENTITY_NAME property with the value
> QUALIFY_ENTITY_NAME_NSPREFIX and still get the duplicate mapping
> exception. The complete exception trace is:
>
> Exception in thread "main" org.hibernate.DuplicateMappingException:
> duplicate import: InterfaceCard refers to both cisco3800.InterfaceCard
> and types.InterfaceCard (try using auto-import="false")
> at org.hibernate.cfg.Mappings.addImport(Mappings.java:141)
> at
> org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues( HbmBinder.java:614)
>
> at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:527)
> at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.jav a:848)
> at
> org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.j ava:2202)
> at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
> at org.hibernate.cfg.Configuration.add(Configuration.java:424)
> at org.hibernate.cfg.Configuration.addXML(Configuration.java:38 4)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:364)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
>
> at org.ziptie.cisco.cs3800Load.doLoadDoc(cs3800Load.java:63)
>
> There are two XSDs (one included by the other) with different
> namespaces, each with a type definition for InterfaceCard. The including
> XSD extends the type of the included namespace. When I look at the
> mapping, the entity-name fields are unique (they have the namespaces
> prefixed) and the descriminator fields are unique (again, the namespace
> is prefixed). In fact, everything is unique with the exception of the
> meta tag for "eclassName" - they are both InterfaceCard without any
> namespace prefixes.
>
> I tried both the default and the "JOINED" Inheritance mapping strategies
> and both result in the same exception although the mappings are
> obviously a bit different. Here is the mapping for these types using the
> default inheritance strategy:
>
> <subclass entity-name="types.InterfaceCard" abstract="false"
> lazy="false" extends="types.Card"
> discriminator-value="types.InterfaceCard">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta
> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
> <list name="port" lazy="true" cascade="all,delete-orphan">
> <key update="true">
> <column name="`interfacecard_port_id`" not-null="false"
> unique="false"/>
> </key>
> <list-index column="`interfacecard_port_idx`"/>
> <one-to-many entity-name="types.Port"/>
> </list>
> </subclass>
> <subclass entity-name="cisco3800.InterfaceCard" abstract="false"
> lazy="false" extends="types.InterfaceCard"
> discriminator-value="cisco3800.InterfaceCard">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
> <property name="icType" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`ictype`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
> <param
> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
> </type>
> </property>
> </subclass>
>
> And here is the mapping for the JOINED strategy:
>
> <joined-subclass entity-name="types.InterfaceCard" abstract="false"
> lazy="false" extends="types.Card" table="`interfacecard`">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta
> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
> <key>
> <column name="`card_id`"/>
> </key>
> <list name="port" lazy="true" cascade="all,delete-orphan">
> <key update="true">
> <column name="`interfacecard_port_id`" not-null="false"
> unique="false"/>
> </key>
> <list-index column="`interfacecard_port_idx`"/>
> <one-to-many entity-name="types.Port"/>
> </list>
> </joined-subclass>
> <joined-subclass entity-name="cisco3800.InterfaceCard"
> abstract="false" lazy="false" extends="types.InterfaceCard"
> table="`interfacecard`">
> <meta attribute="eclassName">InterfaceCard</meta>
> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
> <key>
> <column name="`interfacecard_id`"/>
> </key>
> <property name="icType" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`ictype`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
> <param
> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
> </type>
> </property>
> </joined-subclass>
>
> Like the default inheritance strategy, the entity-names are unique and
> the meta attribute eclassName is not. However, note that the table names
> are the same. That is probably bad mojo.
>
> Outside of hand editing the generated hbm file, is there some other way
> to fix or control this behavior?
>
> Thanks,
>
> Brian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: teneo: Yet another DuplicateMappingException problem [message #601893 is a reply to message #69741] Wed, 31 January 2007 23:13 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I changed to use the statically built hbm.xml file and set auto-import to false. Hibernate was able to load the mapping file and create the tables. So if you can let us set auto-import to false as a persistence option or automatically set it for cases when QUALIFY_ENTITY_NAME is set to use the namespace prefix, that would be cool.

I still have one problem. When I use the JOINED inheritance strategy, it specifies the same table name for the two types. The latter definition overrides the former and I only get a single table.

Brian

Martin Taal wrote:
> I looked in the hibernate source and it seems that auto-import="false"
> can get rid of this error.
> For now this has to be done manually, in the top-tag in the hbm.xml set
> the attribute auto-import="false":
> <hibernate-mapping
> schema="schemaName" (1)
> default-cascade="none|save-update" (2)
> auto-import="true|false" (3)
> package="package.name" (4)
> />
>
> Let me know if this works then I'll add this as an option in Teneo.
>
> gr. Martin
>
> Brian Vetter wrote:
>> I too am having a problem with a Duplicate<appingException being
>> thrown. I have added the QUALIFY_ENTITY_NAME property with the value
>> QUALIFY_ENTITY_NAME_NSPREFIX and still get the duplicate mapping
>> exception. The complete exception trace is:
>>
>> Exception in thread "main" org.hibernate.DuplicateMappingException:
>> duplicate import: InterfaceCard refers to both cisco3800.InterfaceCard
>> and types.InterfaceCard (try using auto-import="false")
>> at org.hibernate.cfg.Mappings.addImport(Mappings.java:141)
>> at
>> org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues( HbmBinder.java:614)
>>
>> at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:527)
>> at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.jav a:848)
>> at
>> org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.j ava:2202)
>> at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
>> at org.hibernate.cfg.Configuration.add(Configuration.java:424)
>> at org.hibernate.cfg.Configuration.addXML(Configuration.java:38 4)
>> at
>> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:364)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
>>
>> at org.ziptie.cisco.cs3800Load.doLoadDoc(cs3800Load.java:63)
>>
>> There are two XSDs (one included by the other) with different
>> namespaces, each with a type definition for InterfaceCard. The
>> including XSD extends the type of the included namespace. When I look
>> at the mapping, the entity-name fields are unique (they have the
>> namespaces prefixed) and the descriminator fields are unique (again,
>> the namespace is prefixed). In fact, everything is unique with the
>> exception of the meta tag for "eclassName" - they are both
>> InterfaceCard without any namespace prefixes.
>>
>> I tried both the default and the "JOINED" Inheritance mapping
>> strategies and both result in the same exception although the mappings
>> are obviously a bit different. Here is the mapping for these types
>> using the default inheritance strategy:
>>
>> <subclass entity-name="types.InterfaceCard" abstract="false"
>> lazy="false" extends="types.Card"
>> discriminator-value="types.InterfaceCard">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta
>> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
>> <list name="port" lazy="true" cascade="all,delete-orphan">
>> <key update="true">
>> <column name="`interfacecard_port_id`"
>> not-null="false" unique="false"/>
>> </key>
>> <list-index column="`interfacecard_port_idx`"/>
>> <one-to-many entity-name="types.Port"/>
>> </list>
>> </subclass>
>> <subclass entity-name="cisco3800.InterfaceCard" abstract="false"
>> lazy="false" extends="types.InterfaceCard"
>> discriminator-value="cisco3800.InterfaceCard">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
>> <property name="icType" lazy="false" not-null="false"
>> insert="true" update="true" unique="false">
>> <column not-null="false" unique="false" name="`ictype`"/>
>> <type
>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>> <param
>> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
>> </type>
>> </property>
>> </subclass>
>>
>> And here is the mapping for the JOINED strategy:
>>
>> <joined-subclass entity-name="types.InterfaceCard"
>> abstract="false" lazy="false" extends="types.Card"
>> table="`interfacecard`">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta
>> attribute="epackage">http://www.ziptie.org/1.0/zipTypes</meta>
>> <key>
>> <column name="`card_id`"/>
>> </key>
>> <list name="port" lazy="true" cascade="all,delete-orphan">
>> <key update="true">
>> <column name="`interfacecard_port_id`"
>> not-null="false" unique="false"/>
>> </key>
>> <list-index column="`interfacecard_port_idx`"/>
>> <one-to-many entity-name="types.Port"/>
>> </list>
>> </joined-subclass>
>> <joined-subclass entity-name="cisco3800.InterfaceCard"
>> abstract="false" lazy="false" extends="types.InterfaceCard"
>> table="`interfacecard`">
>> <meta attribute="eclassName">InterfaceCard</meta>
>> <meta attribute="epackage">http://www.ziptie.org/cisco3800</meta>
>> <key>
>> <column name="`interfacecard_id`"/>
>> </key>
>> <property name="icType" lazy="false" not-null="false"
>> insert="true" update="true" unique="false">
>> <column not-null="false" unique="false" name="`ictype`"/>
>> <type
>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>> <param
>> name="enumClass">org.ziptie.cisco3800.IcTypeType</param>
>> </type>
>> </property>
>> </joined-subclass>
>>
>> Like the default inheritance strategy, the entity-names are unique and
>> the meta attribute eclassName is not. However, note that the table
>> names are the same. That is probably bad mojo.
>>
>> Outside of hand editing the generated hbm file, is there some other
>> way to fix or control this behavior?
>>
>> Thanks,
>>
>> Brian
>
>
Re: teneo: Yet another DuplicateMappingException problem [message #601900 is a reply to message #69761] Thu, 01 February 2007 00:44 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
BTW, I'd like the behavior to be that the name of the tables were prefixed with the namespace prefix. If this isn't the default, I'd like to have a way to control/force it.

Thanks,

Brian

Brian Vetter wrote:
> I changed to use the statically built hbm.xml file and set auto-import
> to false. Hibernate was able to load the mapping file and create the
> tables. So if you can let us set auto-import to false as a persistence
> option or automatically set it for cases when QUALIFY_ENTITY_NAME is set
> to use the namespace prefix, that would be cool.
>
> I still have one problem. When I use the JOINED inheritance strategy, it
> specifies the same table name for the two types. The latter definition
> overrides the former and I only get a single table.
>
> Brian
>
Re: teneo: Yet another DuplicateMappingException problem [message #601907 is a reply to message #69780] Thu, 01 February 2007 05:49 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I'll change the following:
set auto-import to false when qualify-entity names is set to nsprefix
include nsprefix in the default table name in case of qualify entity name

In the meantime you can use a table annotation on the eclass to set a different table name.

Btw, the meta eclass tag is not unique because it also has an accompanying epackage tag.

gr. Martin

Brian Vetter wrote:
> BTW, I'd like the behavior to be that the name of the tables were
> prefixed with the namespace prefix. If this isn't the default, I'd like
> to have a way to control/force it.
>
> Thanks,
>
> Brian
>
> Brian Vetter wrote:
>> I changed to use the statically built hbm.xml file and set auto-import
>> to false. Hibernate was able to load the mapping file and create the
>> tables. So if you can let us set auto-import to false as a persistence
>> option or automatically set it for cases when QUALIFY_ENTITY_NAME is
>> set to use the namespace prefix, that would be cool.
>>
>> I still have one problem. When I use the JOINED inheritance strategy,
>> it specifies the same table name for the two types. The latter
>> definition overrides the former and I only get a single table.
>>
>> Brian
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Teneo: Persistence Mapping XML files for multiple namespaces; was: Yet another DuplicateMappingExcep [message #601921 is a reply to message #69801] Thu, 01 February 2007 17:55 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I'd like to maintain the persistence mappings outside of the original XSD files if possible. I believe I can do this using the PERSISTENCE_XML option to provide a resource file. However, I have some questions on how this will work if there are multiple XSDs with multiple namespaces. Here are the scenarios:

- Each "resource" type has its own XSD and namespace.
- There are several namespaces that are common to all of the resource types. These common namespaces and their type/element definitions are imported into each of the resource type XSDs.
- Resource types can be added dynamically to a system (through either importing new Jars or perhaps in the future, the use of dynamic APIs).
- Each resource type may have their own persistence mapping strategies for the types they introduce.
- Two separate installations/deployments may want to use the core XSDs for resource typing, but may want to have different persistence strategies.

Because of this last point, we want to keep the persistence mapping directives out of the core XSDs and potentially replace the mapping strategies for each of the resource XSDs. Sharing of the XSDs is important. Sharing the persistence mappings is less important and perhaps not possible.

In looking through the example persistence mapping file examples, it wasn't clear to me first if it was possible to have multiple active mapping files. Second, it wasn't clear to me how it would deal with multiple namespaces, especially when the base type names may be the same for two types in different namespaces.

Also, it appears that the separate XML examples are using the mapped ecore types although the modeling dudes here are using XSDs.

Am I missing something important? Any suggestions on how I might best organize the mapping files and the XSDs?

Thanks,

Brian


Martin Taal wrote:
>
> In the meantime you can use a table annotation on the eclass to set a
> different table name.
>
Re: Teneo: Persistence Mapping XML files for multiple namespaces; was: Yet another DuplicateMappingE [message #601928 is a reply to message #69840] Thu, 01 February 2007 20:00 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Brian,
Yes keeping the annotations outside of the xsd is a good approach. It keeps your model clean.

Currently you can only specify one xml file with additional mapping directives. Please enter a
bugzilla if you require support for multiple xml annotation files.

The xml annotation file can contain multiple epackages so this should work fine (see the xsd) for
your case (having eclasses with the same name).

Regarding the mapped ecore type use in the annotation xml. There is no other way but normally you
should be able to easily determine the eclass/efeature name from the xsd element definitions (the
names should be the same).

Btw, the build of today should solve your auto-import and tablename issue.

gr. Martin

Brian Vetter wrote:
> I'd like to maintain the persistence mappings outside of the original
> XSD files if possible. I believe I can do this using the PERSISTENCE_XML
> option to provide a resource file. However, I have some questions on
> how this will work if there are multiple XSDs with multiple namespaces.
> Here are the scenarios:
>
> - Each "resource" type has its own XSD and namespace.
> - There are several namespaces that are common to all of the resource
> types. These common namespaces and their type/element definitions are
> imported into each of the resource type XSDs.
> - Resource types can be added dynamically to a system (through either
> importing new Jars or perhaps in the future, the use of dynamic APIs).
> - Each resource type may have their own persistence mapping strategies
> for the types they introduce.
> - Two separate installations/deployments may want to use the core XSDs
> for resource typing, but may want to have different persistence strategies.
>
> Because of this last point, we want to keep the persistence mapping
> directives out of the core XSDs and potentially replace the mapping
> strategies for each of the resource XSDs. Sharing of the XSDs is
> important. Sharing the persistence mappings is less important and
> perhaps not possible.
>
> In looking through the example persistence mapping file examples, it
> wasn't clear to me first if it was possible to have multiple active
> mapping files. Second, it wasn't clear to me how it would deal with
> multiple namespaces, especially when the base type names may be the same
> for two types in different namespaces.
>
> Also, it appears that the separate XML examples are using the mapped
> ecore types although the modeling dudes here are using XSDs.
>
> Am I missing something important? Any suggestions on how I might best
> organize the mapping files and the XSDs?
>
> Thanks,
>
> Brian
>
>
> Martin Taal wrote:
>>
>> In the meantime you can use a table annotation on the eclass to set a
>> different table name.
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: teneo: Yet another DuplicateMappingException problem [message #602027 is a reply to message #69801] Fri, 02 February 2007 14:30 Go to previous message
JG is currently offline JGFriend
Messages: 51
Registered: July 2009
Member
Martin Taal wrote:
> I'll change the following:
> set auto-import to false when qualify-entity names is set to nsprefix
> include nsprefix in the default table name in case of qualify entity name
>
> In the meantime you can use a table annotation on the eclass to set a
> different table name.
>
> Btw, the meta eclass tag is not unique because it also has an
> accompanying epackage tag.
>


And from one of Brian's messages:


Brian Vetter wrote:

> In looking through the example persistence mapping file examples, it
> wasn't clear to me first if it was possible to have multiple active
> mapping files. Second, it wasn't clear to me how it would deal with
> multiple namespaces, especially when the base type names may be the same
> for two types in different namespaces.




I believe I stumbled across exactly this problem. I have two classes
named "Attribute" intwo different packages. When I simply use Teneo's
default mapping, I get this error:



[INFO ] duplicate import: Attribute->Attribute
[INFO ] Mapping subclass: Attribute -> instance
Exception in thread "main" org.hibernate.DuplicateMappingException:
Duplicate class/entity mapping Attribute
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 12)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addXML(Configuration.java:44 0)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
at paladin.TeneoTest.main(TeneoTest.java:51)


So I figured that Teneo does not qualify the table names, and looked for
a way to influence the mapping. I did this:

<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo">
<epackage namespace-uri="http:///p/m/xml.ecore">
<eclass name="Attribute">
<table name="XMLAttribute"/>
</eclass>
</epackage>
</persistence-mapping>


I set the PERSISTENCE_XML property accordingly and got this one:

DEBUG] located
[http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
[ERROR] Error parsing XML: XML String(1253) Attribute "table" must be
declared for element type "subclass".
Exception in thread "main" org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addXML(Configuration.java:43 8)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
at paladin.TeneoTest.main(TeneoTest.java:51)
Caused by: org.xml.sax.SAXParseException: Attribute "table" must be
declared for element type "subclass".


So I looked at the mapping file that was generated... of all subclass
elements, only ONE actually had a table attribute, the one for my
Attribute that I wanted to rename. All others didn't. So i looked at the
Hibernate-Mapping DTD and was surprised to see that subclass elements
are not even supposed to have table elements.

What am I missing here? Am I using the wrong way to rename the table for
conflicting entities?

I actually would prefer manual conflict resolution instead of having the
table names be qualified (I understand that this is the solution you
have been working on).

Regards

Jürgen
Re: teneo: Yet another DuplicateMappingException problem [message #602036 is a reply to message #70125] Fri, 02 February 2007 14:48 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
In case of the same eclass name occuring in different epackages then you need to set the
PersistenceOptions.QUALIFY_ENTITY_NAME option to PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX.
This will also qualify the table name for all eclasses (added in the release yesterday).
What I understand is that you use a single table inheritance mapping. In this case the table
annotation does not work for a subclass as a subclass is stored in the same table as its superclass.
The table annotation is usefull for joined-subclass inheritance mapping and in case of single-table
for the roots of the inheritance hierarchy.

Teneo should not add a table attribute to a subclass tag (maybe report a warning if a table
annotation is found). Can you enter a bugzilla for that?

gr. Martin

JG wrote:
> Martin Taal wrote:
>> I'll change the following:
>> set auto-import to false when qualify-entity names is set to nsprefix
>> include nsprefix in the default table name in case of qualify entity name
>>
>> In the meantime you can use a table annotation on the eclass to set a
>> different table name.
>>
>> Btw, the meta eclass tag is not unique because it also has an
>> accompanying epackage tag.
>>
>
>
> And from one of Brian's messages:
>
>
> Brian Vetter wrote:
>
>> In looking through the example persistence mapping file examples, it
>> wasn't clear to me first if it was possible to have multiple active
>> mapping files. Second, it wasn't clear to me how it would deal with
>> multiple namespaces, especially when the base type names may be the same
>> for two types in different namespaces.
>
>
>
>
> I believe I stumbled across exactly this problem. I have two classes
> named "Attribute" intwo different packages. When I simply use Teneo's
> default mapping, I get this error:
>
>
>
> [INFO ] duplicate import: Attribute->Attribute
> [INFO ] Mapping subclass: Attribute -> instance
> Exception in thread "main" org.hibernate.DuplicateMappingException:
> Duplicate class/entity mapping Attribute
> at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 12)
> at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:149)
> at org.hibernate.cfg.Configuration.add(Configuration.java:669)
> at org.hibernate.cfg.Configuration.addXML(Configuration.java:44 0)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
> at paladin.TeneoTest.main(TeneoTest.java:51)
>
>
> So I figured that Teneo does not qualify the table names, and looked for
> a way to influence the mapping. I did this:
>
> <persistence-mapping xmlns="http://www.eclipse.org/emft/teneo">
> <epackage namespace-uri="http:///p/m/xml.ecore">
> <eclass name="Attribute">
> <table name="XMLAttribute"/>
> </eclass>
> </epackage>
> </persistence-mapping>
>
>
> I set the PERSISTENCE_XML property accordingly and got this one:
>
> DEBUG] located
> [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
> [ERROR] Error parsing XML: XML String(1253) Attribute "table" must be
> declared for element type "subclass".
> Exception in thread "main" org.hibernate.MappingException: invalid mapping
> at org.hibernate.cfg.Configuration.addXML(Configuration.java:43 8)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.mapModel(HbDataS tore.java:367)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:156)
> at paladin.TeneoTest.main(TeneoTest.java:51)
> Caused by: org.xml.sax.SAXParseException: Attribute "table" must be
> declared for element type "subclass".
>
>
> So I looked at the mapping file that was generated... of all subclass
> elements, only ONE actually had a table attribute, the one for my
> Attribute that I wanted to rename. All others didn't. So i looked at the
> Hibernate-Mapping DTD and was surprised to see that subclass elements
> are not even supposed to have table elements.
>
> What am I missing here? Am I using the wrong way to rename the table for
> conflicting entities?
>
> I actually would prefer manual conflict resolution instead of having the
> table names be qualified (I understand that this is the solution you
> have been working on).
>
> Regards
>
> Jürgen
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Another issue: hibernate.cfg.xml ignored? (was: Re: teneo: Yet another DuplicateMappingException pro [message #602043 is a reply to message #70142] Fri, 02 February 2007 15:29 Go to previous message
JG is currently offline JGFriend
Messages: 51
Registered: July 2009
Member
Martin Taal wrote:
> In case of the same eclass name occuring in different epackages then you
> need to set the PersistenceOptions.QUALIFY_ENTITY_NAME option to
> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX. This will also qualify
> the table name for all eclasses (added in the release yesterday).

> What I understand is that you use a single table inheritance mapping. In
> this case the table annotation does not work for a subclass as a
> subclass is stored in the same table as its superclass.

Funny thing is, some thought like that had already crossed my mind
("Hey, there's only one table, how should that work."), but I thought
that it was a conflict with the type tag in the single table, and that
setting the table override would do the trick.

> The table annotation is usefull for joined-subclass inheritance mapping
> and in case of single-table for the roots of the inheritance hierarchy.

>
> Teneo should not add a table attribute to a subclass tag (maybe report a
> warning if a table annotation is found). Can you enter a bugzilla for that?

Done. :-)


I got another issue: I placed a hibernate.cfg.xml into the root of my
EMF model package structure, in order to configure Hibernate.
Apparently, this file is ignored. Do I have to set hibernate properties
programmatically?


Regards

Jürgen
Re: Another issue: hibernate.cfg.xml ignored? [message #602049 is a reply to message #70162] Fri, 02 February 2007 15:59 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hmm the hibernate.cfg.xml should work afaics (I would need to look in more detail to see why this
would not work). You can also pass all the hibernate configuration properties programmatically using
the setHibernateProperties on the HbDataStore or place a hibernate.properties file in the root of
the classpath. See here:
http://www.elver.org/hibernate/tutorialone/tutorial1_2.html

gr. Martin

JG wrote:
> Martin Taal wrote:
>> In case of the same eclass name occuring in different epackages then you
>> need to set the PersistenceOptions.QUALIFY_ENTITY_NAME option to
>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX. This will also qualify
>> the table name for all eclasses (added in the release yesterday).
>
>> What I understand is that you use a single table inheritance mapping. In
>> this case the table annotation does not work for a subclass as a
>> subclass is stored in the same table as its superclass.
>
> Funny thing is, some thought like that had already crossed my mind
> ("Hey, there's only one table, how should that work."), but I thought
> that it was a conflict with the type tag in the single table, and that
> setting the table override would do the trick.
>
>> The table annotation is usefull for joined-subclass inheritance mapping
>> and in case of single-table for the roots of the inheritance hierarchy.
>
>> Teneo should not add a table attribute to a subclass tag (maybe report a
>> warning if a table annotation is found). Can you enter a bugzilla for that?
>
> Done. :-)
>
>
> I got another issue: I placed a hibernate.cfg.xml into the root of my
> EMF model package structure, in order to configure Hibernate.
> Apparently, this file is ignored. Do I have to set hibernate properties
> programmatically?
>
>
> Regards
>
> Jürgen


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:[Teneo] Newbie question: Do I really have to register all my packages to Teneo manually? (using data
Next Topic:"Repeated column in mapping for entity"
Goto Forum:
  


Current Time: Tue Apr 16 16:48:22 GMT 2024

Powered by FUDForum. Page generated in 0.07566 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top