Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Strange DuplicateMappingException with Teneo
Strange DuplicateMappingException with Teneo [message #62659] Fri, 24 November 2006 14:01 Go to next message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi all,

I am working on an application using EMF with the teneo project. I
followed the quick start guide on the elver.org site and it all works
fine for me. But when I am using my own EMF model, I messed up with an
DuplicateMappingException while trying to initialize the db scheme:

------------------------------------------------------------ -
org.hibernate.DuplicateMappingException: duplicate import: Error refers
to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
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:360)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
at ...TestSomething.testSomething(TestSomething.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
------------------------------------------------------------ -

The strange thing is that I used the property
PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the mapped
classes but anyway I get the exception! Here is my code wich I use to
init the db scheme:

------------------------------------------------------------ -
// Set the database information, Environment is
org.hibernate.cfg.Environment
final Properties props = new Properties();
props.setProperty(Environment.DRIVER, db_driver);
props.setProperty(Environment.USER, db_user);
props.setProperty(Environment.URL, "jdbc:mysql://127.0.0.1:3306/"
+ db_name);
props.setProperty(Environment.PASS, db_pass);
props.setProperty(Environment.DIALECT,
org.hibernate.dialect.MySQLInnoDBDialect.class.getName());

// persistance properties
final Properties persistanceProps = new Properties();
// HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);

// create the HbDataStore
HbDataStore hbds =
HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);

// sets its epackages stored in this datastore
hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
WorkflowPackage.eINSTANCE});

// set the relational database to use and other properties
// to set Teneo specific options call hbds.setPersistenceProperties
hbds.setHibernateProperties(props);

// HERE ARE THE PROPS TO SET
hbds.setPersistenceProperties(persistanceProps);


// initialize, also creates the database tables
hbds.initialize();
------------------------------------------------------------ -

Here is the snippet of the hibernate mapping file which were generated
for my EMF Model by teneo:

....
<subclass entity-name="...context.Error" abstract="false" lazy="false"
extends="...context.Class" discriminator-value="Error">
<meta attribute="eclassName">Error</meta>
<meta attribute="epackage">http:///.../context.ecore</meta>
</subclass>
....
<subclass entity-name="...base.flow.Error" abstract="false" lazy="false"
extends="de.visualrules.base.flow.Statement" discriminator-value="Error">
<meta attribute="eclassName">Error</meta>
<meta attribute="epackage">http:///.../base/flow.ecore</meta>
<many-to-one name="message"
entity-name="...base.expression.Expression" cascade="all" lazy="false"
insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`expression_message_id`"/>
</many-to-one>
</subclass>
....

I think the problem is that the value of 'discriminator-value' is the
same for the '...flow.Error' class and the '...context.Error' class. I
havent found a property that influences this behavior. For me it is not
clear why teneo explicitly set the attribute 'discriminator-value'
because Hibernate uses the fully qulified class name per default (I think).

Are there any solutions for this problem?

thanks in advance, sascha
Re: Strange DuplicateMappingException with Teneo [message #62686 is a reply to message #62659] Fri, 24 November 2006 14:19 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sascha,
Can you try to manually repair the discriminator-value in the hbm file and then tell teneo to use
the hbm file (there is an option for that)?
Anyway this seems to be a bug, the discriminator value should also use the qualified name. But if
you can test it then I am sure that this is the cause of this issue.

The reason that discriminator is set is that in this way dynamic emf is supported (where all objects
can be of the same class but representing different types/eclasses).

gr. Martin

Sascha Theves wrote:
> Hi all,
>
> I am working on an application using EMF with the teneo project. I
> followed the quick start guide on the elver.org site and it all works
> fine for me. But when I am using my own EMF model, I messed up with an
> DuplicateMappingException while trying to initialize the db scheme:
>
> ------------------------------------------------------------ -
> org.hibernate.DuplicateMappingException: duplicate import: Error refers
> to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
> 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:360)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>
> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
> at ...TestSomething.testSomething(TestSomething.java:26)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:585)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>
> ------------------------------------------------------------ -
>
> The strange thing is that I used the property
> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the mapped
> classes but anyway I get the exception! Here is my code wich I use to
> init the db scheme:
>
> ------------------------------------------------------------ -
> // Set the database information, Environment is
> org.hibernate.cfg.Environment
> final Properties props = new Properties();
> props.setProperty(Environment.DRIVER, db_driver);
> props.setProperty(Environment.USER, db_user);
> props.setProperty(Environment.URL, "jdbc:mysql://127.0.0.1:3306/"
> + db_name);
> props.setProperty(Environment.PASS, db_pass);
> props.setProperty(Environment.DIALECT,
> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>
> // persistance properties
> final Properties persistanceProps = new Properties();
> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>
> // create the HbDataStore
> HbDataStore hbds =
> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>
> // sets its epackages stored in this datastore
> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
> WorkflowPackage.eINSTANCE});
>
> // set the relational database to use and other properties
> // to set Teneo specific options call hbds.setPersistenceProperties
> hbds.setHibernateProperties(props);
>
> // HERE ARE THE PROPS TO SET
> hbds.setPersistenceProperties(persistanceProps);
>
>
> // initialize, also creates the database tables
> hbds.initialize();
> ------------------------------------------------------------ -
>
> Here is the snippet of the hibernate mapping file which were generated
> for my EMF Model by teneo:
>
> ....
> <subclass entity-name="...context.Error" abstract="false" lazy="false"
> extends="...context.Class" discriminator-value="Error">
> <meta attribute="eclassName">Error</meta>
> <meta attribute="epackage">http:///.../context.ecore</meta>
> </subclass>
> ....
> <subclass entity-name="...base.flow.Error" abstract="false" lazy="false"
> extends="de.visualrules.base.flow.Statement" discriminator-value="Error">
> <meta attribute="eclassName">Error</meta>
> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
> <many-to-one name="message"
> entity-name="...base.expression.Expression" cascade="all" lazy="false"
> insert="true" update="true" not-null="false">
> <column not-null="false" unique="false"
> name="`expression_message_id`"/>
> </many-to-one>
> </subclass>
> ....
>
> I think the problem is that the value of 'discriminator-value' is the
> same for the '...flow.Error' class and the '...context.Error' class. I
> havent found a property that influences this behavior. For me it is not
> clear why teneo explicitly set the attribute 'discriminator-value'
> because Hibernate uses the fully qulified class name per default (I think).
>
> Are there any solutions for this problem?
>
> thanks in advance, sascha
>
>
>


--

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: Strange DuplicateMappingException with Teneo [message #62710 is a reply to message #62686] Fri, 24 November 2006 16:56 Go to previous messageGo to next message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi Martin,

I tried the workaround you described below. I have copied the hbm file
in the src folder (not in an particular java package) of my model plugin
and told teneo the use this file (via the
PersistenceOptions.USE_MAPPING_FILE Property). But it ended up in the
following NPE:


java.lang.NullPointerException
at
org.eclipse.emf.teneo.hibernate.HbDataStore.computeReferers( HbDataStore.java:727)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:162)
...



I looked at the code and tried to find out where the NPE comes from. The
snippet from which the NPE comes from is pasted below:

if (ef == null) { // TODO can this happen?
isContainer = prop.getCascadeStyle().hasOrphanDelete()
|| prop.getCascadeStyle() == CascadeStyle.ALL;
if (((Collection) prop.getValue()).getElement() instanceof
OneToMany) {
final Collection coll = (Collection) prop.getValue();
toEntity = ((OneToMany)
coll.getElement()).getReferencedEntityName();
} else if (((Collection) prop.getValue()).getElement() instanceof
ManyToOne) {
final Collection coll = (Collection) prop.getValue();
toEntity = ((ManyToOne)
coll.getElement()).getReferencedEntityName();
} else {
throw new HbMapperException("Type "
+ ((Collection) prop.getValue()).getElement().getClass().getName()
+ " not supported");
}
}

It seems that 'ef' (EStructuralFeature) is null. Then I looked where ef
comes from:

final EStructuralFeature ef =
StoreUtil.getEStructuralFeature(pc.getEntityName(), prop.getName(),
getEPackages());

This method returns null for the EStructuralFeature although the
pc.getEntityName() ,prop.getName() and getEPackages() returning the
right values.

Any ideas where this comes from?

thanks for your help!

Sascha



Martin Taal schrieb:
> Hi Sascha,
> Can you try to manually repair the discriminator-value in the hbm file
> and then tell teneo to use the hbm file (there is an option for that)?
> Anyway this seems to be a bug, the discriminator value should also use
> the qualified name. But if you can test it then I am sure that this is
> the cause of this issue.
>
> The reason that discriminator is set is that in this way dynamic emf is
> supported (where all objects can be of the same class but representing
> different types/eclasses).
>
> gr. Martin
>
> Sascha Theves wrote:
>> Hi all,
>>
>> I am working on an application using EMF with the teneo project. I
>> followed the quick start guide on the elver.org site and it all works
>> fine for me. But when I am using my own EMF model, I messed up with an
>> DuplicateMappingException while trying to initialize the db scheme:
>>
>> ------------------------------------------------------------ -
>> org.hibernate.DuplicateMappingException: duplicate import: Error
>> refers to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
>> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
>> 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:360)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>>
>> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
>> at ...TestSomething.testSomething(TestSomething.java:26)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>
>> at java.lang.reflect.Method.invoke(Method.java:585)
>> at junit.framework.TestCase.runTest(TestCase.java:154)
>> at junit.framework.TestCase.runBare(TestCase.java:127)
>> at junit.framework.TestResult$1.protect(TestResult.java:106)
>> at junit.framework.TestResult.runProtected(TestResult.java:124)
>> at junit.framework.TestResult.run(TestResult.java:109)
>> at junit.framework.TestCase.run(TestCase.java:118)
>> at
>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>>
>> ------------------------------------------------------------ -
>>
>> The strange thing is that I used the property
>> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the mapped
>> classes but anyway I get the exception! Here is my code wich I use to
>> init the db scheme:
>>
>> ------------------------------------------------------------ -
>> // Set the database information, Environment is
>> org.hibernate.cfg.Environment
>> final Properties props = new Properties();
>> props.setProperty(Environment.DRIVER, db_driver);
>> props.setProperty(Environment.USER, db_user);
>> props.setProperty(Environment.URL,
>> "jdbc:mysql://127.0.0.1:3306/" + db_name);
>> props.setProperty(Environment.PASS, db_pass);
>> props.setProperty(Environment.DIALECT,
>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>
>> // persistance properties
>> final Properties persistanceProps = new Properties();
>> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
>> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>>
>> // create the HbDataStore
>> HbDataStore hbds =
>> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>>
>> // sets its epackages stored in this datastore
>> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
>> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
>> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
>> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
>> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
>> WorkflowPackage.eINSTANCE});
>>
>> // set the relational database to use and other properties
>> // to set Teneo specific options call hbds.setPersistenceProperties
>> hbds.setHibernateProperties(props);
>>
>> // HERE ARE THE PROPS TO SET
>> hbds.setPersistenceProperties(persistanceProps);
>>
>>
>> // initialize, also creates the database tables
>> hbds.initialize();
>> ------------------------------------------------------------ -
>>
>> Here is the snippet of the hibernate mapping file which were generated
>> for my EMF Model by teneo:
>>
>> ....
>> <subclass entity-name="...context.Error" abstract="false" lazy="false"
>> extends="...context.Class" discriminator-value="Error">
>> <meta attribute="eclassName">Error</meta>
>> <meta attribute="epackage">http:///.../context.ecore</meta>
>> </subclass>
>> ....
>> <subclass entity-name="...base.flow.Error" abstract="false"
>> lazy="false" extends="....flow.Statement"
>> discriminator-value="Error">
>> <meta attribute="eclassName">Error</meta>
>> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
>> <many-to-one name="message"
>> entity-name="...base.expression.Expression" cascade="all" lazy="false"
>> insert="true" update="true" not-null="false">
>> <column not-null="false" unique="false"
>> name="`expression_message_id`"/>
>> </many-to-one>
>> </subclass>
>> ....
>>
>> I think the problem is that the value of 'discriminator-value' is the
>> same for the '...flow.Error' class and the '...context.Error' class. I
>> havent found a property that influences this behavior. For me it is
>> not clear why teneo explicitly set the attribute 'discriminator-value'
>> because Hibernate uses the fully qulified class name per default (I
>> think).
>>
>> Are there any solutions for this problem?
>>
>> thanks in advance, sascha
>>
>>
>>
>
>
Re: Strange DuplicateMappingException with Teneo [message #62734 is a reply to message #62710] Fri, 24 November 2006 17:18 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sascha,
Hmmm, I need to check but I think that the referer computation does not take into account that the
entityname is qualified (a bug).
Can you send me (by email or on the newsgroup) the ecore file? I will look at the discriminator
issue and this last issue you have.

Can you enter a bugzilla for the discriminator issue (afaics this must be changed anyway).

gr. Martin

Sascha Theves wrote:
> Hi Martin,
>
> I tried the workaround you described below. I have copied the hbm file
> in the src folder (not in an particular java package) of my model plugin
> and told teneo the use this file (via the
> PersistenceOptions.USE_MAPPING_FILE Property). But it ended up in the
> following NPE:
>
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.computeReferers( HbDataStore.java:727)
>
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:162)
>
> ...
>
>
>
> I looked at the code and tried to find out where the NPE comes from. The
> snippet from which the NPE comes from is pasted below:
>
> if (ef == null) { // TODO can this happen?
> isContainer =
> prop.getCascadeStyle().hasOrphanDelete()
> || prop.getCascadeStyle() ==
> CascadeStyle.ALL;
> if (((Collection)
> prop.getValue()).getElement() instanceof OneToMany) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((OneToMany)
> coll.getElement()).getReferencedEntityName();
> } else if (((Collection)
> prop.getValue()).getElement() instanceof ManyToOne) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((ManyToOne)
> coll.getElement()).getReferencedEntityName();
> } else {
> throw new HbMapperException("Type "
> + ((Collection)
> prop.getValue()).getElement().getClass().getName()
> + " not supported");
> }
> }
>
> It seems that 'ef' (EStructuralFeature) is null. Then I looked where ef
> comes from:
>
> final EStructuralFeature ef =
> StoreUtil.getEStructuralFeature(pc.getEntityName(), prop.getName(),
> getEPackages());
>
> This method returns null for the EStructuralFeature although the
> pc.getEntityName() ,prop.getName() and getEPackages() returning the
> right values.
>
> Any ideas where this comes from?
>
> thanks for your help!
>
> Sascha
>
>
>
> Martin Taal schrieb:
>> Hi Sascha,
>> Can you try to manually repair the discriminator-value in the hbm file
>> and then tell teneo to use the hbm file (there is an option for that)?
>> Anyway this seems to be a bug, the discriminator value should also use
>> the qualified name. But if you can test it then I am sure that this is
>> the cause of this issue.
>>
>> The reason that discriminator is set is that in this way dynamic emf
>> is supported (where all objects can be of the same class but
>> representing different types/eclasses).
>>
>> gr. Martin
>>
>> Sascha Theves wrote:
>>> Hi all,
>>>
>>> I am working on an application using EMF with the teneo project. I
>>> followed the quick start guide on the elver.org site and it all works
>>> fine for me. But when I am using my own EMF model, I messed up with
>>> an DuplicateMappingException while trying to initialize the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> org.hibernate.DuplicateMappingException: duplicate import: Error
>>> refers to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
>>> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
>>> 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:360)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>>>
>>> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
>>> at ...TestSomething.testSomething(TestSomething.java:26)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>
>>> at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:585)
>>> at junit.framework.TestCase.runTest(TestCase.java:154)
>>> at junit.framework.TestCase.runBare(TestCase.java:127)
>>> at junit.framework.TestResult$1.protect(TestResult.java:106)
>>> at junit.framework.TestResult.runProtected(TestResult.java:124)
>>> at junit.framework.TestResult.run(TestResult.java:109)
>>> at junit.framework.TestCase.run(TestCase.java:118)
>>> at
>>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>>>
>>> ------------------------------------------------------------ -
>>>
>>> The strange thing is that I used the property
>>> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the
>>> mapped classes but anyway I get the exception! Here is my code wich I
>>> use to init the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> // Set the database information, Environment is
>>> org.hibernate.cfg.Environment
>>> final Properties props = new Properties();
>>> props.setProperty(Environment.DRIVER, db_driver);
>>> props.setProperty(Environment.USER, db_user);
>>> props.setProperty(Environment.URL,
>>> "jdbc:mysql://127.0.0.1:3306/" + db_name);
>>> props.setProperty(Environment.PASS, db_pass);
>>> props.setProperty(Environment.DIALECT,
>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>
>>> // persistance properties
>>> final Properties persistanceProps = new Properties();
>>> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
>>> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
>>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>>>
>>> // create the HbDataStore
>>> HbDataStore hbds =
>>> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>>>
>>> // sets its epackages stored in this datastore
>>> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
>>> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
>>> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
>>> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
>>> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
>>> WorkflowPackage.eINSTANCE});
>>>
>>> // set the relational database to use and other properties
>>> // to set Teneo specific options call
>>> hbds.setPersistenceProperties
>>> hbds.setHibernateProperties(props);
>>>
>>> // HERE ARE THE PROPS TO SET
>>> hbds.setPersistenceProperties(persistanceProps);
>>>
>>>
>>> // initialize, also creates the database tables
>>> hbds.initialize();
>>> ------------------------------------------------------------ -
>>>
>>> Here is the snippet of the hibernate mapping file which were
>>> generated for my EMF Model by teneo:
>>>
>>> ....
>>> <subclass entity-name="...context.Error" abstract="false"
>>> lazy="false" extends="...context.Class" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../context.ecore</meta>
>>> </subclass>
>>> ....
>>> <subclass entity-name="...base.flow.Error" abstract="false"
>>> lazy="false" extends="....flow.Statement" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
>>> <many-to-one name="message"
>>> entity-name="...base.expression.Expression" cascade="all"
>>> lazy="false" insert="true" update="true" not-null="false">
>>> <column not-null="false" unique="false"
>>> name="`expression_message_id`"/>
>>> </many-to-one>
>>> </subclass>
>>> ....
>>>
>>> I think the problem is that the value of 'discriminator-value' is the
>>> same for the '...flow.Error' class and the '...context.Error' class.
>>> I havent found a property that influences this behavior. For me it is
>>> not clear why teneo explicitly set the attribute
>>> 'discriminator-value' because Hibernate uses the fully qulified class
>>> name per default (I think).
>>>
>>> Are there any solutions for this problem?
>>>
>>> thanks in advance, sascha
>>>
>>>
>>>
>>
>>


--

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: Strange DuplicateMappingException with Teneo [message #62796 is a reply to message #62710] Sun, 26 November 2006 22:54 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sascha,
After some more testing on my side. I think the npe is caused because the nsprefix contains dots
(.). I have changed it to handle this better (not yet checked in).
You can test it by changing the nsprefix of the epackage to something without dots (so instead of .
http:///.../base/flow.ecore have http://base/flow.ecore as nsprefix). You need to regenerate the
source code and hbm file also to test this.

gr. Martin

Sascha Theves wrote:
> Hi Martin,
>
> I tried the workaround you described below. I have copied the hbm file
> in the src folder (not in an particular java package) of my model plugin
> and told teneo the use this file (via the
> PersistenceOptions.USE_MAPPING_FILE Property). But it ended up in the
> following NPE:
>
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.computeReferers( HbDataStore.java:727)
>
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:162)
>
> ...
>
>
>
> I looked at the code and tried to find out where the NPE comes from. The
> snippet from which the NPE comes from is pasted below:
>
> if (ef == null) { // TODO can this happen?
> isContainer =
> prop.getCascadeStyle().hasOrphanDelete()
> || prop.getCascadeStyle() ==
> CascadeStyle.ALL;
> if (((Collection)
> prop.getValue()).getElement() instanceof OneToMany) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((OneToMany)
> coll.getElement()).getReferencedEntityName();
> } else if (((Collection)
> prop.getValue()).getElement() instanceof ManyToOne) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((ManyToOne)
> coll.getElement()).getReferencedEntityName();
> } else {
> throw new HbMapperException("Type "
> + ((Collection)
> prop.getValue()).getElement().getClass().getName()
> + " not supported");
> }
> }
>
> It seems that 'ef' (EStructuralFeature) is null. Then I looked where ef
> comes from:
>
> final EStructuralFeature ef =
> StoreUtil.getEStructuralFeature(pc.getEntityName(), prop.getName(),
> getEPackages());
>
> This method returns null for the EStructuralFeature although the
> pc.getEntityName() ,prop.getName() and getEPackages() returning the
> right values.
>
> Any ideas where this comes from?
>
> thanks for your help!
>
> Sascha
>
>
>
> Martin Taal schrieb:
>> Hi Sascha,
>> Can you try to manually repair the discriminator-value in the hbm file
>> and then tell teneo to use the hbm file (there is an option for that)?
>> Anyway this seems to be a bug, the discriminator value should also use
>> the qualified name. But if you can test it then I am sure that this is
>> the cause of this issue.
>>
>> The reason that discriminator is set is that in this way dynamic emf
>> is supported (where all objects can be of the same class but
>> representing different types/eclasses).
>>
>> gr. Martin
>>
>> Sascha Theves wrote:
>>> Hi all,
>>>
>>> I am working on an application using EMF with the teneo project. I
>>> followed the quick start guide on the elver.org site and it all works
>>> fine for me. But when I am using my own EMF model, I messed up with
>>> an DuplicateMappingException while trying to initialize the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> org.hibernate.DuplicateMappingException: duplicate import: Error
>>> refers to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
>>> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
>>> 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:360)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>>>
>>> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
>>> at ...TestSomething.testSomething(TestSomething.java:26)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>
>>> at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:585)
>>> at junit.framework.TestCase.runTest(TestCase.java:154)
>>> at junit.framework.TestCase.runBare(TestCase.java:127)
>>> at junit.framework.TestResult$1.protect(TestResult.java:106)
>>> at junit.framework.TestResult.runProtected(TestResult.java:124)
>>> at junit.framework.TestResult.run(TestResult.java:109)
>>> at junit.framework.TestCase.run(TestCase.java:118)
>>> at
>>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>>>
>>> ------------------------------------------------------------ -
>>>
>>> The strange thing is that I used the property
>>> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the
>>> mapped classes but anyway I get the exception! Here is my code wich I
>>> use to init the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> // Set the database information, Environment is
>>> org.hibernate.cfg.Environment
>>> final Properties props = new Properties();
>>> props.setProperty(Environment.DRIVER, db_driver);
>>> props.setProperty(Environment.USER, db_user);
>>> props.setProperty(Environment.URL,
>>> "jdbc:mysql://127.0.0.1:3306/" + db_name);
>>> props.setProperty(Environment.PASS, db_pass);
>>> props.setProperty(Environment.DIALECT,
>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>
>>> // persistance properties
>>> final Properties persistanceProps = new Properties();
>>> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
>>> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
>>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>>>
>>> // create the HbDataStore
>>> HbDataStore hbds =
>>> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>>>
>>> // sets its epackages stored in this datastore
>>> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
>>> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
>>> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
>>> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
>>> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
>>> WorkflowPackage.eINSTANCE});
>>>
>>> // set the relational database to use and other properties
>>> // to set Teneo specific options call
>>> hbds.setPersistenceProperties
>>> hbds.setHibernateProperties(props);
>>>
>>> // HERE ARE THE PROPS TO SET
>>> hbds.setPersistenceProperties(persistanceProps);
>>>
>>>
>>> // initialize, also creates the database tables
>>> hbds.initialize();
>>> ------------------------------------------------------------ -
>>>
>>> Here is the snippet of the hibernate mapping file which were
>>> generated for my EMF Model by teneo:
>>>
>>> ....
>>> <subclass entity-name="...context.Error" abstract="false"
>>> lazy="false" extends="...context.Class" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../context.ecore</meta>
>>> </subclass>
>>> ....
>>> <subclass entity-name="...base.flow.Error" abstract="false"
>>> lazy="false" extends="....flow.Statement" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
>>> <many-to-one name="message"
>>> entity-name="...base.expression.Expression" cascade="all"
>>> lazy="false" insert="true" update="true" not-null="false">
>>> <column not-null="false" unique="false"
>>> name="`expression_message_id`"/>
>>> </many-to-one>
>>> </subclass>
>>> ....
>>>
>>> I think the problem is that the value of 'discriminator-value' is the
>>> same for the '...flow.Error' class and the '...context.Error' class.
>>> I havent found a property that influences this behavior. For me it is
>>> not clear why teneo explicitly set the attribute
>>> 'discriminator-value' because Hibernate uses the fully qulified class
>>> name per default (I think).
>>>
>>> Are there any solutions for this problem?
>>>
>>> thanks in advance, sascha
>>>
>>>
>>>
>>
>>


--

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: Strange DuplicateMappingException with Teneo [message #596140 is a reply to message #62659] Fri, 24 November 2006 14:19 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sascha,
Can you try to manually repair the discriminator-value in the hbm file and then tell teneo to use
the hbm file (there is an option for that)?
Anyway this seems to be a bug, the discriminator value should also use the qualified name. But if
you can test it then I am sure that this is the cause of this issue.

The reason that discriminator is set is that in this way dynamic emf is supported (where all objects
can be of the same class but representing different types/eclasses).

gr. Martin

Sascha Theves wrote:
> Hi all,
>
> I am working on an application using EMF with the teneo project. I
> followed the quick start guide on the elver.org site and it all works
> fine for me. But when I am using my own EMF model, I messed up with an
> DuplicateMappingException while trying to initialize the db scheme:
>
> ------------------------------------------------------------ -
> org.hibernate.DuplicateMappingException: duplicate import: Error refers
> to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
> 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:360)
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>
> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
> at ...TestSomething.testSomething(TestSomething.java:26)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:585)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>
> ------------------------------------------------------------ -
>
> The strange thing is that I used the property
> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the mapped
> classes but anyway I get the exception! Here is my code wich I use to
> init the db scheme:
>
> ------------------------------------------------------------ -
> // Set the database information, Environment is
> org.hibernate.cfg.Environment
> final Properties props = new Properties();
> props.setProperty(Environment.DRIVER, db_driver);
> props.setProperty(Environment.USER, db_user);
> props.setProperty(Environment.URL, "jdbc:mysql://127.0.0.1:3306/"
> + db_name);
> props.setProperty(Environment.PASS, db_pass);
> props.setProperty(Environment.DIALECT,
> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>
> // persistance properties
> final Properties persistanceProps = new Properties();
> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>
> // create the HbDataStore
> HbDataStore hbds =
> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>
> // sets its epackages stored in this datastore
> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
> WorkflowPackage.eINSTANCE});
>
> // set the relational database to use and other properties
> // to set Teneo specific options call hbds.setPersistenceProperties
> hbds.setHibernateProperties(props);
>
> // HERE ARE THE PROPS TO SET
> hbds.setPersistenceProperties(persistanceProps);
>
>
> // initialize, also creates the database tables
> hbds.initialize();
> ------------------------------------------------------------ -
>
> Here is the snippet of the hibernate mapping file which were generated
> for my EMF Model by teneo:
>
> ....
> <subclass entity-name="...context.Error" abstract="false" lazy="false"
> extends="...context.Class" discriminator-value="Error">
> <meta attribute="eclassName">Error</meta>
> <meta attribute="epackage">http:///.../context.ecore</meta>
> </subclass>
> ....
> <subclass entity-name="...base.flow.Error" abstract="false" lazy="false"
> extends="de.visualrules.base.flow.Statement" discriminator-value="Error">
> <meta attribute="eclassName">Error</meta>
> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
> <many-to-one name="message"
> entity-name="...base.expression.Expression" cascade="all" lazy="false"
> insert="true" update="true" not-null="false">
> <column not-null="false" unique="false"
> name="`expression_message_id`"/>
> </many-to-one>
> </subclass>
> ....
>
> I think the problem is that the value of 'discriminator-value' is the
> same for the '...flow.Error' class and the '...context.Error' class. I
> havent found a property that influences this behavior. For me it is not
> clear why teneo explicitly set the attribute 'discriminator-value'
> because Hibernate uses the fully qulified class name per default (I think).
>
> Are there any solutions for this problem?
>
> thanks in advance, sascha
>
>
>


--

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: Strange DuplicateMappingException with Teneo [message #596150 is a reply to message #62686] Fri, 24 November 2006 16:56 Go to previous message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi Martin,

I tried the workaround you described below. I have copied the hbm file
in the src folder (not in an particular java package) of my model plugin
and told teneo the use this file (via the
PersistenceOptions.USE_MAPPING_FILE Property). But it ended up in the
following NPE:


java.lang.NullPointerException
at
org.eclipse.emf.teneo.hibernate.HbDataStore.computeReferers( HbDataStore.java:727)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:162)
...



I looked at the code and tried to find out where the NPE comes from. The
snippet from which the NPE comes from is pasted below:

if (ef == null) { // TODO can this happen?
isContainer = prop.getCascadeStyle().hasOrphanDelete()
|| prop.getCascadeStyle() == CascadeStyle.ALL;
if (((Collection) prop.getValue()).getElement() instanceof
OneToMany) {
final Collection coll = (Collection) prop.getValue();
toEntity = ((OneToMany)
coll.getElement()).getReferencedEntityName();
} else if (((Collection) prop.getValue()).getElement() instanceof
ManyToOne) {
final Collection coll = (Collection) prop.getValue();
toEntity = ((ManyToOne)
coll.getElement()).getReferencedEntityName();
} else {
throw new HbMapperException("Type "
+ ((Collection) prop.getValue()).getElement().getClass().getName()
+ " not supported");
}
}

It seems that 'ef' (EStructuralFeature) is null. Then I looked where ef
comes from:

final EStructuralFeature ef =
StoreUtil.getEStructuralFeature(pc.getEntityName(), prop.getName(),
getEPackages());

This method returns null for the EStructuralFeature although the
pc.getEntityName() ,prop.getName() and getEPackages() returning the
right values.

Any ideas where this comes from?

thanks for your help!

Sascha



Martin Taal schrieb:
> Hi Sascha,
> Can you try to manually repair the discriminator-value in the hbm file
> and then tell teneo to use the hbm file (there is an option for that)?
> Anyway this seems to be a bug, the discriminator value should also use
> the qualified name. But if you can test it then I am sure that this is
> the cause of this issue.
>
> The reason that discriminator is set is that in this way dynamic emf is
> supported (where all objects can be of the same class but representing
> different types/eclasses).
>
> gr. Martin
>
> Sascha Theves wrote:
>> Hi all,
>>
>> I am working on an application using EMF with the teneo project. I
>> followed the quick start guide on the elver.org site and it all works
>> fine for me. But when I am using my own EMF model, I messed up with an
>> DuplicateMappingException while trying to initialize the db scheme:
>>
>> ------------------------------------------------------------ -
>> org.hibernate.DuplicateMappingException: duplicate import: Error
>> refers to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
>> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
>> 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:360)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>>
>> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
>> at ...TestSomething.testSomething(TestSomething.java:26)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>
>> at java.lang.reflect.Method.invoke(Method.java:585)
>> at junit.framework.TestCase.runTest(TestCase.java:154)
>> at junit.framework.TestCase.runBare(TestCase.java:127)
>> at junit.framework.TestResult$1.protect(TestResult.java:106)
>> at junit.framework.TestResult.runProtected(TestResult.java:124)
>> at junit.framework.TestResult.run(TestResult.java:109)
>> at junit.framework.TestCase.run(TestCase.java:118)
>> at
>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>>
>> ------------------------------------------------------------ -
>>
>> The strange thing is that I used the property
>> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the mapped
>> classes but anyway I get the exception! Here is my code wich I use to
>> init the db scheme:
>>
>> ------------------------------------------------------------ -
>> // Set the database information, Environment is
>> org.hibernate.cfg.Environment
>> final Properties props = new Properties();
>> props.setProperty(Environment.DRIVER, db_driver);
>> props.setProperty(Environment.USER, db_user);
>> props.setProperty(Environment.URL,
>> "jdbc:mysql://127.0.0.1:3306/" + db_name);
>> props.setProperty(Environment.PASS, db_pass);
>> props.setProperty(Environment.DIALECT,
>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>
>> // persistance properties
>> final Properties persistanceProps = new Properties();
>> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
>> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>>
>> // create the HbDataStore
>> HbDataStore hbds =
>> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>>
>> // sets its epackages stored in this datastore
>> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
>> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
>> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
>> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
>> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
>> WorkflowPackage.eINSTANCE});
>>
>> // set the relational database to use and other properties
>> // to set Teneo specific options call hbds.setPersistenceProperties
>> hbds.setHibernateProperties(props);
>>
>> // HERE ARE THE PROPS TO SET
>> hbds.setPersistenceProperties(persistanceProps);
>>
>>
>> // initialize, also creates the database tables
>> hbds.initialize();
>> ------------------------------------------------------------ -
>>
>> Here is the snippet of the hibernate mapping file which were generated
>> for my EMF Model by teneo:
>>
>> ....
>> <subclass entity-name="...context.Error" abstract="false" lazy="false"
>> extends="...context.Class" discriminator-value="Error">
>> <meta attribute="eclassName">Error</meta>
>> <meta attribute="epackage">http:///.../context.ecore</meta>
>> </subclass>
>> ....
>> <subclass entity-name="...base.flow.Error" abstract="false"
>> lazy="false" extends="....flow.Statement"
>> discriminator-value="Error">
>> <meta attribute="eclassName">Error</meta>
>> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
>> <many-to-one name="message"
>> entity-name="...base.expression.Expression" cascade="all" lazy="false"
>> insert="true" update="true" not-null="false">
>> <column not-null="false" unique="false"
>> name="`expression_message_id`"/>
>> </many-to-one>
>> </subclass>
>> ....
>>
>> I think the problem is that the value of 'discriminator-value' is the
>> same for the '...flow.Error' class and the '...context.Error' class. I
>> havent found a property that influences this behavior. For me it is
>> not clear why teneo explicitly set the attribute 'discriminator-value'
>> because Hibernate uses the fully qulified class name per default (I
>> think).
>>
>> Are there any solutions for this problem?
>>
>> thanks in advance, sascha
>>
>>
>>
>
>
Re: Strange DuplicateMappingException with Teneo [message #596158 is a reply to message #62710] Fri, 24 November 2006 17:18 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sascha,
Hmmm, I need to check but I think that the referer computation does not take into account that the
entityname is qualified (a bug).
Can you send me (by email or on the newsgroup) the ecore file? I will look at the discriminator
issue and this last issue you have.

Can you enter a bugzilla for the discriminator issue (afaics this must be changed anyway).

gr. Martin

Sascha Theves wrote:
> Hi Martin,
>
> I tried the workaround you described below. I have copied the hbm file
> in the src folder (not in an particular java package) of my model plugin
> and told teneo the use this file (via the
> PersistenceOptions.USE_MAPPING_FILE Property). But it ended up in the
> following NPE:
>
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.computeReferers( HbDataStore.java:727)
>
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:162)
>
> ...
>
>
>
> I looked at the code and tried to find out where the NPE comes from. The
> snippet from which the NPE comes from is pasted below:
>
> if (ef == null) { // TODO can this happen?
> isContainer =
> prop.getCascadeStyle().hasOrphanDelete()
> || prop.getCascadeStyle() ==
> CascadeStyle.ALL;
> if (((Collection)
> prop.getValue()).getElement() instanceof OneToMany) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((OneToMany)
> coll.getElement()).getReferencedEntityName();
> } else if (((Collection)
> prop.getValue()).getElement() instanceof ManyToOne) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((ManyToOne)
> coll.getElement()).getReferencedEntityName();
> } else {
> throw new HbMapperException("Type "
> + ((Collection)
> prop.getValue()).getElement().getClass().getName()
> + " not supported");
> }
> }
>
> It seems that 'ef' (EStructuralFeature) is null. Then I looked where ef
> comes from:
>
> final EStructuralFeature ef =
> StoreUtil.getEStructuralFeature(pc.getEntityName(), prop.getName(),
> getEPackages());
>
> This method returns null for the EStructuralFeature although the
> pc.getEntityName() ,prop.getName() and getEPackages() returning the
> right values.
>
> Any ideas where this comes from?
>
> thanks for your help!
>
> Sascha
>
>
>
> Martin Taal schrieb:
>> Hi Sascha,
>> Can you try to manually repair the discriminator-value in the hbm file
>> and then tell teneo to use the hbm file (there is an option for that)?
>> Anyway this seems to be a bug, the discriminator value should also use
>> the qualified name. But if you can test it then I am sure that this is
>> the cause of this issue.
>>
>> The reason that discriminator is set is that in this way dynamic emf
>> is supported (where all objects can be of the same class but
>> representing different types/eclasses).
>>
>> gr. Martin
>>
>> Sascha Theves wrote:
>>> Hi all,
>>>
>>> I am working on an application using EMF with the teneo project. I
>>> followed the quick start guide on the elver.org site and it all works
>>> fine for me. But when I am using my own EMF model, I messed up with
>>> an DuplicateMappingException while trying to initialize the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> org.hibernate.DuplicateMappingException: duplicate import: Error
>>> refers to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
>>> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
>>> 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:360)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>>>
>>> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
>>> at ...TestSomething.testSomething(TestSomething.java:26)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>
>>> at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:585)
>>> at junit.framework.TestCase.runTest(TestCase.java:154)
>>> at junit.framework.TestCase.runBare(TestCase.java:127)
>>> at junit.framework.TestResult$1.protect(TestResult.java:106)
>>> at junit.framework.TestResult.runProtected(TestResult.java:124)
>>> at junit.framework.TestResult.run(TestResult.java:109)
>>> at junit.framework.TestCase.run(TestCase.java:118)
>>> at
>>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>>>
>>> ------------------------------------------------------------ -
>>>
>>> The strange thing is that I used the property
>>> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the
>>> mapped classes but anyway I get the exception! Here is my code wich I
>>> use to init the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> // Set the database information, Environment is
>>> org.hibernate.cfg.Environment
>>> final Properties props = new Properties();
>>> props.setProperty(Environment.DRIVER, db_driver);
>>> props.setProperty(Environment.USER, db_user);
>>> props.setProperty(Environment.URL,
>>> "jdbc:mysql://127.0.0.1:3306/" + db_name);
>>> props.setProperty(Environment.PASS, db_pass);
>>> props.setProperty(Environment.DIALECT,
>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>
>>> // persistance properties
>>> final Properties persistanceProps = new Properties();
>>> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
>>> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
>>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>>>
>>> // create the HbDataStore
>>> HbDataStore hbds =
>>> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>>>
>>> // sets its epackages stored in this datastore
>>> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
>>> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
>>> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
>>> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
>>> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
>>> WorkflowPackage.eINSTANCE});
>>>
>>> // set the relational database to use and other properties
>>> // to set Teneo specific options call
>>> hbds.setPersistenceProperties
>>> hbds.setHibernateProperties(props);
>>>
>>> // HERE ARE THE PROPS TO SET
>>> hbds.setPersistenceProperties(persistanceProps);
>>>
>>>
>>> // initialize, also creates the database tables
>>> hbds.initialize();
>>> ------------------------------------------------------------ -
>>>
>>> Here is the snippet of the hibernate mapping file which were
>>> generated for my EMF Model by teneo:
>>>
>>> ....
>>> <subclass entity-name="...context.Error" abstract="false"
>>> lazy="false" extends="...context.Class" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../context.ecore</meta>
>>> </subclass>
>>> ....
>>> <subclass entity-name="...base.flow.Error" abstract="false"
>>> lazy="false" extends="....flow.Statement" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
>>> <many-to-one name="message"
>>> entity-name="...base.expression.Expression" cascade="all"
>>> lazy="false" insert="true" update="true" not-null="false">
>>> <column not-null="false" unique="false"
>>> name="`expression_message_id`"/>
>>> </many-to-one>
>>> </subclass>
>>> ....
>>>
>>> I think the problem is that the value of 'discriminator-value' is the
>>> same for the '...flow.Error' class and the '...context.Error' class.
>>> I havent found a property that influences this behavior. For me it is
>>> not clear why teneo explicitly set the attribute
>>> 'discriminator-value' because Hibernate uses the fully qulified class
>>> name per default (I think).
>>>
>>> Are there any solutions for this problem?
>>>
>>> thanks in advance, sascha
>>>
>>>
>>>
>>
>>


--

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: Strange DuplicateMappingException with Teneo [message #596187 is a reply to message #62710] Sun, 26 November 2006 22:54 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sascha,
After some more testing on my side. I think the npe is caused because the nsprefix contains dots
(.). I have changed it to handle this better (not yet checked in).
You can test it by changing the nsprefix of the epackage to something without dots (so instead of .
http:///.../base/flow.ecore have http://base/flow.ecore as nsprefix). You need to regenerate the
source code and hbm file also to test this.

gr. Martin

Sascha Theves wrote:
> Hi Martin,
>
> I tried the workaround you described below. I have copied the hbm file
> in the src folder (not in an particular java package) of my model plugin
> and told teneo the use this file (via the
> PersistenceOptions.USE_MAPPING_FILE Property). But it ended up in the
> following NPE:
>
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.computeReferers( HbDataStore.java:727)
>
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:162)
>
> ...
>
>
>
> I looked at the code and tried to find out where the NPE comes from. The
> snippet from which the NPE comes from is pasted below:
>
> if (ef == null) { // TODO can this happen?
> isContainer =
> prop.getCascadeStyle().hasOrphanDelete()
> || prop.getCascadeStyle() ==
> CascadeStyle.ALL;
> if (((Collection)
> prop.getValue()).getElement() instanceof OneToMany) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((OneToMany)
> coll.getElement()).getReferencedEntityName();
> } else if (((Collection)
> prop.getValue()).getElement() instanceof ManyToOne) {
> final Collection coll = (Collection)
> prop.getValue();
> toEntity = ((ManyToOne)
> coll.getElement()).getReferencedEntityName();
> } else {
> throw new HbMapperException("Type "
> + ((Collection)
> prop.getValue()).getElement().getClass().getName()
> + " not supported");
> }
> }
>
> It seems that 'ef' (EStructuralFeature) is null. Then I looked where ef
> comes from:
>
> final EStructuralFeature ef =
> StoreUtil.getEStructuralFeature(pc.getEntityName(), prop.getName(),
> getEPackages());
>
> This method returns null for the EStructuralFeature although the
> pc.getEntityName() ,prop.getName() and getEPackages() returning the
> right values.
>
> Any ideas where this comes from?
>
> thanks for your help!
>
> Sascha
>
>
>
> Martin Taal schrieb:
>> Hi Sascha,
>> Can you try to manually repair the discriminator-value in the hbm file
>> and then tell teneo to use the hbm file (there is an option for that)?
>> Anyway this seems to be a bug, the discriminator value should also use
>> the qualified name. But if you can test it then I am sure that this is
>> the cause of this issue.
>>
>> The reason that discriminator is set is that in this way dynamic emf
>> is supported (where all objects can be of the same class but
>> representing different types/eclasses).
>>
>> gr. Martin
>>
>> Sascha Theves wrote:
>>> Hi all,
>>>
>>> I am working on an application using EMF with the teneo project. I
>>> followed the quick start guide on the elver.org site and it all works
>>> fine for me. But when I am using my own EMF model, I messed up with
>>> an DuplicateMappingException while trying to initialize the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> org.hibernate.DuplicateMappingException: duplicate import: Error
>>> refers to both ...context.Error and ...flow.Error (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.bindSubclass(HbmBinder.java:809)
>>> at org.hibernate.cfg.HbmBinder.handleSubclass(HbmBinder.java:22 10)
>>> 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:360)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.HbDataStore.initialize(HbDat aStore.java:155)
>>>
>>> at ...DataStoreManager.initDataStore(DataStoreManager.java:73)
>>> at ...TestSomething.testSomething(TestSomething.java:26)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>
>>> at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:585)
>>> at junit.framework.TestCase.runTest(TestCase.java:154)
>>> at junit.framework.TestCase.runBare(TestCase.java:127)
>>> at junit.framework.TestResult$1.protect(TestResult.java:106)
>>> at junit.framework.TestResult.runProtected(TestResult.java:124)
>>> at junit.framework.TestResult.run(TestResult.java:109)
>>> at junit.framework.TestCase.run(TestCase.java:118)
>>> at
>>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>>>
>>> at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>>>
>>> ------------------------------------------------------------ -
>>>
>>> The strange thing is that I used the property
>>> PersistenceOptions.QUALIFY_ENTITY_NAME to get an prefix for the
>>> mapped classes but anyway I get the exception! Here is my code wich I
>>> use to init the db scheme:
>>>
>>> ------------------------------------------------------------ -
>>> // Set the database information, Environment is
>>> org.hibernate.cfg.Environment
>>> final Properties props = new Properties();
>>> props.setProperty(Environment.DRIVER, db_driver);
>>> props.setProperty(Environment.USER, db_user);
>>> props.setProperty(Environment.URL,
>>> "jdbc:mysql://127.0.0.1:3306/" + db_name);
>>> props.setProperty(Environment.PASS, db_pass);
>>> props.setProperty(Environment.DIALECT,
>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>
>>> // persistance properties
>>> final Properties persistanceProps = new Properties();
>>> // HERE IS THE THE QUALIFY_ENTITY_NAME OPTION
>>> persistanceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
>>> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX);
>>>
>>> // create the HbDataStore
>>> HbDataStore hbds =
>>> HbHelper.INSTANCE.createRegisterDataStore(hb_datastore);
>>>
>>> // sets its epackages stored in this datastore
>>> hbds.setEPackages(new EPackage[] {BasePackage.eINSTANCE,
>>> RulePackage.eINSTANCE, FlowPackage.eINSTANCE,
>>> ContextPackage.eINSTANCE, BindingPackage.eINSTANCE,
>>> EnvironmentPackage.eINSTANCE, ExpressionPackage.eINSTANCE,
>>> MessagePackage.eINSTANCE, TestPackage.eINSTANCE,
>>> WorkflowPackage.eINSTANCE});
>>>
>>> // set the relational database to use and other properties
>>> // to set Teneo specific options call
>>> hbds.setPersistenceProperties
>>> hbds.setHibernateProperties(props);
>>>
>>> // HERE ARE THE PROPS TO SET
>>> hbds.setPersistenceProperties(persistanceProps);
>>>
>>>
>>> // initialize, also creates the database tables
>>> hbds.initialize();
>>> ------------------------------------------------------------ -
>>>
>>> Here is the snippet of the hibernate mapping file which were
>>> generated for my EMF Model by teneo:
>>>
>>> ....
>>> <subclass entity-name="...context.Error" abstract="false"
>>> lazy="false" extends="...context.Class" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../context.ecore</meta>
>>> </subclass>
>>> ....
>>> <subclass entity-name="...base.flow.Error" abstract="false"
>>> lazy="false" extends="....flow.Statement" discriminator-value="Error">
>>> <meta attribute="eclassName">Error</meta>
>>> <meta attribute="epackage">http:///.../base/flow.ecore</meta>
>>> <many-to-one name="message"
>>> entity-name="...base.expression.Expression" cascade="all"
>>> lazy="false" insert="true" update="true" not-null="false">
>>> <column not-null="false" unique="false"
>>> name="`expression_message_id`"/>
>>> </many-to-one>
>>> </subclass>
>>> ....
>>>
>>> I think the problem is that the value of 'discriminator-value' is the
>>> same for the '...flow.Error' class and the '...context.Error' class.
>>> I havent found a property that influences this behavior. For me it is
>>> not clear why teneo explicitly set the attribute
>>> 'discriminator-value' because Hibernate uses the fully qulified class
>>> name per default (I think).
>>>
>>> Are there any solutions for this problem?
>>>
>>> thanks in advance, sascha
>>>
>>>
>>>
>>
>>


--

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 - two different hibernate databases in one ResourceSet
Next Topic:[Transaction] Command is not executed
Goto Forum:
  


Current Time: Fri Feb 26 09:51:19 GMT 2021

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

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

Back to the top