[Teneo] Several different mappings for one EClass [message #527361] |
Thu, 15 April 2010 03:51 |
Nikita Missing name Messages: 32 Registered: October 2009 |
Member |
|
|
Hello,
I was wondering if Teneo allows defining more than one mapping for one EClass? For example, with Hibernate I can map the same java class in multiple ways, to different tables:
<hibernate-mapping package="com.sandbox">
<class name="Person" entity-name="Doctor" table="Doctor">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" type="string" column="name"/>
</class>
<class name="Person" entity-name="Patient" table="Patient">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" type="string" column="name"/>
</class>
</hibernate-mapping>
I tried doing something similar with Teneo by providing a custom mapping file via the option PersistenceOptions.MAPPING_FILE_PATH, but I got the following exception:
2010-04-14 23:41:42,302 [main] ERROR org.eclipse.emf.teneo.classloader.StoreClassLoadException - Class for name exception
java.lang.ClassNotFoundException: Patient
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.eclipse.emf.teneo.classloader.ClassLoaderResolver.classForName(ClassLoaderResolver.java:50)
at org.eclipse.emf.teneo.ERuntime.getEClass(ERuntime.java:383)
at org.eclipse.emf.teneo.hibernate.HbUtil.getPropertyAccessor(HbUtil.java:133)
at org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.getPropertyAccessor(EMFTuplizer.java:323)
at org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.buildPropertyGetter(EMFTuplizer.java:184)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:141)
at org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.<init>(EMFTuplizer.java:84)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:82)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:72)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSessionFactory(HbSessionDataStore.java:205)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:90)
at com.sandbox.SandboxTeneoMapping.testTeneoConfiguration(SandboxTeneoMapping.java:78)
at com.sandbox.SandboxTeneoMapping.main(SandboxTeneoMapping.java:26)
Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:82)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:72)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSessionFactory(HbSessionDataStore.java:205)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:90)
at com.sandbox.SandboxTeneoMapping.testTeneoConfiguration(SandboxTeneoMapping.java:78)
at com.sandbox.SandboxTeneoMapping.main(SandboxTeneoMapping.java:26)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
... 12 more
Caused by: java.lang.NullPointerException
at org.eclipse.emf.teneo.util.StoreUtil.getEStructuralFeature(StoreUtil.java:369)
at org.eclipse.emf.teneo.hibernate.HbUtil.getPropertyAccessor(HbUtil.java:135)
at org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.getPropertyAccessor(EMFTuplizer.java:323)
at org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.buildPropertyGetter(EMFTuplizer.java:184)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:141)
This is the mapping file that I used for Teneo:
<hibernate-mapping auto-import="false">
<class entity-name="Patient" abstract="false" lazy="false" discriminator-value="PersonType" table="`patient`">
<meta attribute="eclassName">PersonType</meta>
<meta attribute="epackage">http://www.example.com/test/SandboxTeneoMapping</meta>
<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
<meta attribute="syntheticId">true</meta>
<generator class="native"/>
</id>
<discriminator type="string">
<column name="dtype" index="persontypedtype" length="255" not-null="true"/>
</discriminator>
<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`name`"/>
</property>
</class>
<class entity-name="Doctor" abstract="false" lazy="false" discriminator-value="PersonType" table="`doctor`">
<meta attribute="eclassName">PersonType</meta>
<meta attribute="epackage">http://www.example.com/test/SandboxTeneoMapping</meta>
<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
<meta attribute="syntheticId">true</meta>
<generator class="native"/>
</id>
<discriminator type="string">
<column name="dtype" index="persontypedtype" length="255" not-null="true"/>
</discriminator>
<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`name`"/>
</property>
</class>
</hibernate-mapping>
Thank you!
Nikita
|
|
|
Re: [Teneo] Several different mappings for one EClass [message #527443 is a reply to message #527361] |
Thu, 15 April 2010 09:31 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Nikita,
Something what for sure is not possible is to have Teneo generate different mappings for one eclass. But you use a
manual mapping approach, still I think it will be difficult.
To workaround the failure you see below, one thing you can try is to implement your own entitynamestrategy. This
strategy is responsible for translating entitynames to eclasses and back. In your case you want to support multiple
entity names for one eclass, so probably you need to support this there somehow.
http://wiki.eclipse.org/Teneo/Hibernate/Extensions#EntityNam eStrategy_ExtensionPoint_.28org.eclipse.emf.teneo.mapping.st rategy.EntityNameStrategy.29
btw, another thing I noticed in your manual mapping is that you don't specify the classname.
To let Teneo generate mappings with class names you can set this property: teneo.mapping.also_map_as_class
to "false"
gr. Martin
Nikita wrote:
> Hello,
>
> I was wondering if Teneo allows defining more than one mapping for one
> EClass? For example, with Hibernate I can map the same java class in
> multiple ways, to different tables:
>
>
> <hibernate-mapping package="com.sandbox">
> <class name="Person" entity-name="Doctor" table="Doctor">
> <id name="id" column="id">
> <generator class="native"/>
> </id>
> <property name="name" type="string" column="name"/>
> </class>
>
> <class name="Person" entity-name="Patient" table="Patient">
> <id name="id" column="id">
> <generator class="native"/>
> </id>
> <property name="name" type="string" column="name"/>
> </class>
> </hibernate-mapping>
>
>
> I tried doing something similar with Teneo by providing a custom mapping
> file via the option PersistenceOptions.MAPPING_FILE_PATH, but I got the
> following exception:
>
>
> 2010-04-14 23:41:42,302 [main] ERROR
> org.eclipse.emf.teneo.classloader.StoreClassLoadException - Class for
> name exception java.lang.ClassNotFoundException: Patient
> at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316 )
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:247)
> at
> org.eclipse.emf.teneo.classloader.ClassLoaderResolver.classF orName(ClassLoaderResolver.java:50)
>
> at org.eclipse.emf.teneo.ERuntime.getEClass(ERuntime.java:383)
> at
> org.eclipse.emf.teneo.hibernate.HbUtil.getPropertyAccessor(H bUtil.java:133)
> at
> org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.getProp ertyAccessor(EMFTuplizer.java:323)
>
> at
> org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.buildPr opertyGetter(EMFTuplizer.java:184)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:141)
>
> at
> org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.<init>(EMFTuplizer.java:84)
>
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e
> Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstructorAccessorImpl.java:27)
>
> at java.lang.reflect.Constructor.newInstance(Constructor.java:5 13)
> at
> org.hibernate.tuple.entity.EntityTuplizerFactory.constructTu plizer(EntityTuplizerFactory.java:107)
>
> at
> org.hibernate.tuple.entity.EntityTuplizerFactory.constructTu plizer(EntityTuplizerFactory.java:82)
>
> at
> org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping . <init>(EntityEntityModeToTuplizerMapping.java:72)
>
> at
> org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
> at
> org.hibernate.persister.entity.AbstractEntityPersister.<init >(AbstractEntityPersister.java:456)
>
> at
> org.hibernate.persister.entity.SingleTableEntityPersister.<init >(SingleTableEntityPersister.java:131)
>
> at
> org.hibernate.persister.PersisterFactory.createClassPersiste r(PersisterFactory.java:84)
>
> at
> org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
> at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configur ation.java:1341)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSess ionFactory(HbSessionDataStore.java:205)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:90)
>
> at
> com.sandbox.SandboxTeneoMapping.testTeneoConfiguration(Sandb oxTeneoMapping.java:78)
>
> at com.sandbox.SandboxTeneoMapping.main(SandboxTeneoMapping.jav a:26)
> Exception in thread "main" org.hibernate.HibernateException: Unable to
> instantiate default tuplizer
> [org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer]
> at
> org.hibernate.tuple.entity.EntityTuplizerFactory.constructTu plizer(EntityTuplizerFactory.java:110)
>
> at
> org.hibernate.tuple.entity.EntityTuplizerFactory.constructTu plizer(EntityTuplizerFactory.java:82)
>
> at
> org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping . <init>(EntityEntityModeToTuplizerMapping.java:72)
>
> at
> org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
> at
> org.hibernate.persister.entity.AbstractEntityPersister.<init >(AbstractEntityPersister.java:456)
>
> at
> org.hibernate.persister.entity.SingleTableEntityPersister.<init >(SingleTableEntityPersister.java:131)
>
> at
> org.hibernate.persister.PersisterFactory.createClassPersiste r(PersisterFactory.java:84)
>
> at
> org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
> at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configur ation.java:1341)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSess ionFactory(HbSessionDataStore.java:205)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:90)
>
> at
> com.sandbox.SandboxTeneoMapping.testTeneoConfiguration(Sandb oxTeneoMapping.java:78)
>
> at com.sandbox.SandboxTeneoMapping.main(SandboxTeneoMapping.jav a:26)
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e
> Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstructorAccessorImpl.java:27)
>
> at java.lang.reflect.Constructor.newInstance(Constructor.java:5 13)
> at
> org.hibernate.tuple.entity.EntityTuplizerFactory.constructTu plizer(EntityTuplizerFactory.java:107)
>
> ... 12 more
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.emf.teneo.util.StoreUtil.getEStructuralFeature(S toreUtil.java:369)
>
> at
> org.eclipse.emf.teneo.hibernate.HbUtil.getPropertyAccessor(H bUtil.java:135)
> at
> org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.getProp ertyAccessor(EMFTuplizer.java:323)
>
> at
> org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.buildPr opertyGetter(EMFTuplizer.java:184)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:141)
>
>
>
> This is the mapping file that I used for Teneo:
>
> <hibernate-mapping auto-import="false">
> <class entity-name="Patient" abstract="false" lazy="false"
> discriminator-value="PersonType" table="`patient`">
> <meta attribute="eclassName">PersonType</meta>
> <meta
> attribute="epackage">http://www.example.com/test/SandboxTeneoMapping</meta>
> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
> <meta attribute="syntheticId">true</meta>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="dtype" index="persontypedtype" length="255"
> not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`name`"/>
> </property>
> </class>
>
> <class entity-name="Doctor" abstract="false" lazy="false"
> discriminator-value="PersonType" table="`doctor`">
> <meta attribute="eclassName">PersonType</meta>
> <meta
> attribute="epackage">http://www.example.com/test/SandboxTeneoMapping</meta>
> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
> <meta attribute="syntheticId">true</meta>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="dtype" index="persontypedtype" length="255"
> not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`name`"/>
> </property>
> </class>
> </hibernate-mapping>
>
>
> Thank you!
> Nikita
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
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] Several different mappings for one EClass [message #527506 is a reply to message #527443] |
Thu, 15 April 2010 13:40 |
Nikita Missing name Messages: 32 Registered: October 2009 |
Member |
|
|
Hi Martin,
Thank you for the quick reply! I will try with a custom EntityNameStrategy.
I didn't understand how the ALSO_MAP_AS_CLASS option works. For me, the hibernate mapping XML that's generated by Teneo is exactly the same regardless of whether I set this option to "true" or "false". I don't generate code from the Ecore, so that's probably the reason?
These are all the options that I pass in:
hbCfg.setProperty(Environment.HBM2DDL_AUTO, "update");
props.setProperty(PersistenceOptions.MAP_DOCUMENT_ROOT, "false");
props.setProperty(PersistenceOptions.EAV_MAPPING, "false");
props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRATEGY, "unique");
props.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY, "ejb3");
props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true");
props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "true");
When I manually edited my hibernate mapping file to have the attribute name="PersonType" on the class elements, I got this exception (looks like Hibernate then tries to actually instantiate a java class with the name PersonType):
Exception in thread "main" org.hibernate.MappingException: entity class not found: PersonType
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:122)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:191)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:136)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSessionFactory(HbSessionDataStore.java:205)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:90)
at com.sandbox.SandboxTeneoMapping.testTeneoConfiguration(SandboxTeneoMapping.java:78)
at com.sandbox.SandboxTeneoMapping.main(SandboxTeneoMapping.java:26)
Caused by: java.lang.ClassNotFoundException: PersonType
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:119)
... 12 more
Thank you,
Nikita
|
|
|
Re: [Teneo] Several different mappings for one EClass [message #527620 is a reply to message #527506] |
Thu, 15 April 2010 18:34 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Nikita,
Ha yes sorry the default for the ALSO_MAP_AS_CLASS is true. You should see things like this in your mapping:
<class name=" org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.libra ry.impl.BookImpl "
the name attribute should be a fully qualified class name of the class, both class mappings should refer to the same
class name (the impl class of the EClass).
gr. Martin
Nikita wrote:
> Hi Martin,
>
> Thank you for the quick reply! I will try with a custom EntityNameStrategy.
>
> I didn't understand how the ALSO_MAP_AS_CLASS option works. For me, the
> hibernate mapping XML that's generated by Teneo is exactly the same
> regardless of whether I set this option to "true" or "false". I don't
> generate code from the Ecore, so that's probably the reason?
>
> These are all the options that I pass in:
>
> hbCfg.setProperty(Environment.HBM2DDL_AUTO, "update");
> props.setProperty(PersistenceOptions.MAP_DOCUMENT_ROOT, "false");
> props.setProperty(PersistenceOptions.EAV_MAPPING, "false");
> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
> "unique");
> props.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRAT EGY,
> "ejb3");
>
> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
> "true");
> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "true");
>
>
> When I manually edited my hibernate mapping file to have the attribute
> name="PersonType" on the class elements, I got this exception (looks
> like Hibernate then tries to actually instantiate a java class with the
> name PersonType):
>
>
> Exception in thread "main" org.hibernate.MappingException: entity class
> not found: PersonType
> at
> org.hibernate.mapping.PersistentClass.getMappedClass(Persist entClass.java:122)
>
> at
> org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactor y.java:191)
> at
> org.hibernate.tuple.PropertyFactory.buildIdentifierProperty( PropertyFactory.java:67)
>
> at
> org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:136)
> at
> org.hibernate.persister.entity.AbstractEntityPersister.<init >(AbstractEntityPersister.java:456)
>
> at
> org.hibernate.persister.entity.SingleTableEntityPersister.<init >(SingleTableEntityPersister.java:131)
>
> at
> org.hibernate.persister.PersisterFactory.createClassPersiste r(PersisterFactory.java:84)
>
> at
> org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
> at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configur ation.java:1341)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSess ionFactory(HbSessionDataStore.java:205)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:90)
>
> at
> com.sandbox.SandboxTeneoMapping.testTeneoConfiguration(Sandb oxTeneoMapping.java:78)
>
> at com.sandbox.SandboxTeneoMapping.main(SandboxTeneoMapping.jav a:26)
> Caused by: java.lang.ClassNotFoundException: PersonType
> at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316 )
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:169)
> at
> org.hibernate.util.ReflectHelper.classForName(ReflectHelper. java:192)
> at
> org.hibernate.mapping.PersistentClass.getMappedClass(Persist entClass.java:119)
>
> ... 12 more
>
>
> Thank you,
> Nikita
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
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
|
|
|
Powered by
FUDForum. Page generated in 0.03025 seconds