Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Using @Embedded
[Teneo] Using @Embedded [message #988344] Thu, 29 November 2012 13:43 Go to next message
Ben Tenne is currently offline Ben Tenne
Messages: 49
Registered: October 2009
Member
Hi,

I've been experimenting with @Embedded and have been unable to get things working. I've got a Horse that optionally contains a Saddle, i.e.

Horse <>--> 0..1 Saddle

I'll try to show what's happening with some file excerpts; Hopefully I've included enough context for it to make sense.

Here's some ECore. Note that Horse.saddle is annotated with @Embedded and the Saddle class is annotated with @Embeddable.

  <eClassifiers xsi:type="ecore:EClass" name="Horse">

  ...
  
    <eStructuralFeatures xsi:type="ecore:EReference" name="saddle" eType="//Saddle" containment="true" resolveProxies="false">
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Embedded"/>
      </eAnnotations>
    </eStructuralFeatures>
	
  ...

  <eClassifiers xsi:type="ecore:EClass" name="Saddle">
  
  ...
  
    <eAnnotations source="teneo.jpa">
      <details key="value" value="@Embeddable"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="color" eType="//color_SaddleType">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="color"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
	
  <eClassifiers xsi:type="ecore:EDataType" name="color_SaddleType" instanceClassName="java.lang.String">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="color_Saddle_._type"/>
      <details key="baseType" value="http://www.eclipse.org/emf/2003/XMLType#string"/>
      <details key="maxLength" value="50"/>
    </eAnnotations>
  </eClassifiers>


So, a Horse has id/version and a horseCode attribute. It also has a reference ('saddle') to Saddle, that's marked @Embedded. Saddle has just a 'color' attribute.

The resulting HBM seems to make sense:

	<class name="com.example.newbury.impl.HorseImpl" entity-name="newbury.Horse" abstract="false" lazy="false" discriminator-value="com.example.newbury.Horse" table="`DPS_1_NWBRY_HORSE`">
		<meta attribute="eclassName">Horse</meta>
		<meta attribute="epackage">http://example.com/newbury</meta>
		<id name="dpsId" type="java.lang.Long">
			<column not-null="false" unique="false" name="`DPS_ID`"/>
			<generator class="native"/>
		</id>
		<discriminator column="`DTYPE`" type="string"/>
		<version name="dpsVersion" type="java.lang.Long">
			<column not-null="false" unique="false" name="`DPS_VERSION`"/>
		</version>
		<property name="horseCode" lazy="false" insert="true" update="true" not-null="true" unique="true" type="java.lang.String">
			<column not-null="true" unique="true" name="`HORSECODE`" length="50"/>
		</property>
		<component name="saddle" class="com.example.newbury.impl.SaddleImpl">
			<property name="color" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
				<column not-null="false" unique="false" name="`COLOR`" length="50"/>
			</property>
		</component>
	</class>


So, it's correctly embedded the 'color' attribute from Saddle into Horse. The resulting database table looks fine too.

However, I then get problems when I try to initialise the datastore:

[EDITED 30 Nov 2012: Corrected package name in the following exception message]


java.lang.IllegalArgumentException: No EClass found using com.example.newbury.impl.SaddleImpl 
	at org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy.toEClass(QualifyingEntityNameStrategy.java:99)
	at org.eclipse.emf.teneo.hibernate.HbDataStore.setComponentTuplizer(HbDataStore.java:633)
	at org.eclipse.emf.teneo.hibernate.HbDataStore.setTuplizer(HbDataStore.java:611)
	at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataStore(HbDataStore.java:255)
	at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:78)


Am I obviously doing something wrong? I hope I've included enough context for it to make sense.

Regards,
Ben.

[Updated on: Fri, 30 November 2012 11:47]

Report message to a moderator

Re: [Teneo] Using @Embedded [message #988398 is a reply to message #988344] Thu, 29 November 2012 17:58 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Ben,
Teneo tries to map from the instance class to the eclass. That seems to go wrong, can you set the instance class in the
eclass and see if that helps?
(normally this is done automatically when creating a genmodel or generating code)

gr. Martin

On 11/29/2012 02:43 PM, Ben Tenne wrote:
> Hi,
>
> I've been experimenting with @Embedded and have been unable to get things working. I've got a Horse that optionally
> contains a Saddle, i.e.
>
> Horse <>--> 0..1 Saddle
>
> I'll try to show what's happening with some file excerpts; Hopefully I've included enough context for it to make sense.
>
> Here's some ECore. Note that Horse.saddle is annotated with @Embedded and the Saddle class is annotated with @Embeddable.
>
>
> <eClassifiers xsi:type="ecore:EClass" name="Horse">
>
> ...
>
> <eStructuralFeatures xsi:type="ecore:EReference" name="saddle" eType="//Saddle" containment="true"
> resolveProxies="false">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Embedded"/>
> </eAnnotations>
> </eStructuralFeatures>
>
> ...
>
> <eClassifiers xsi:type="ecore:EClass" name="Saddle">
>
> ...
>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Embeddable"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="color" eType="//color_SaddleType">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="color"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
> <eClassifiers xsi:type="ecore:EDataType" name="color_SaddleType" instanceClassName="java.lang.String">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="color_Saddle_._type"/>
> <details key="baseType" value="http://www.eclipse.org/emf/2003/XMLType#string"/>
> <details key="maxLength" value="50"/>
> </eAnnotations>
> </eClassifiers>
>
>
> So, a Horse has id/version and a horseCode attribute. It also has a reference ('saddle') to Saddle, that's marked
> @Embedded. Saddle has just a 'color' attribute.
>
> The resulting HBM seems to make sense:
>
>
> <class name="com.example.newbury.impl.HorseImpl" entity-name="newbury.Horse" abstract="false" lazy="false"
> discriminator-value="com.example.newbury.Horse" table="`DPS_1_NWBRY_HORSE`">
> <meta attribute="eclassName">Horse</meta>
> <meta attribute="epackage">http://example.com/newbury</meta>
> <id name="dpsId" type="java.lang.Long">
> <column not-null="false" unique="false" name="`DPS_ID`"/>
> <generator class="native"/>
> </id>
> <discriminator column="`DTYPE`" type="string"/>
> <version name="dpsVersion" type="java.lang.Long">
> <column not-null="false" unique="false" name="`DPS_VERSION`"/>
> </version>
> <property name="horseCode" lazy="false" insert="true" update="true" not-null="true" unique="true"
> type="java.lang.String">
> <column not-null="true" unique="true" name="`HORSECODE`" length="50"/>
> </property>
> <component name="saddle" class="com.example.newbury.impl.SaddleImpl">
> <property name="color" lazy="false" insert="true" update="true" not-null="false" unique="false"
> type="java.lang.String">
> <column not-null="false" unique="false" name="`COLOR`" length="50"/>
> </property>
> </component>
> </class>
>
>
> So, it's correctly embedded the 'color' attribute from Saddle into Horse. The resulting database table looks fine too.
>
> However, I then get problems when I try to initialise the datastore:
>
>
> java.lang.IllegalArgumentException: No EClass found using com.example.ordermodel.impl.SaddleImpl
> at
> org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy.toEClass(QualifyingEntityNameStrategy.java:99)
> at org.eclipse.emf.teneo.hibernate.HbDataStore.setComponentTuplizer(HbDataStore.java:633)
> at org.eclipse.emf.teneo.hibernate.HbDataStore.setTuplizer(HbDataStore.java:611)
> at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataStore(HbDataStore.java:255)
> at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:78)
>
>
> Am I obviously doing something wrong? I hope I've included enough context for it to make sense.
>
> Regards,
> Ben.


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Using @Embedded [message #988528 is a reply to message #988344] Fri, 30 November 2012 11:24 Go to previous messageGo to next message
Ben Tenne is currently offline Ben Tenne
Messages: 49
Registered: October 2009
Member
Hi Martin,

Thanks for the reply.

Firstly, I need to correct an error in my last post. Here's the exception. The difference is that the fully qualified name is com.example.newbury.impl.SaddleImpl. Previously, I incorrectly put 'ordermodel' instead of 'newbury'. I'd pasted in the stack trace from a different run of the test, where I had the classes in a different package, thus it didn't match up with the Hibernate mapping.

java.lang.IllegalArgumentException: No EClass found using com.example.newbury.impl.SaddleImpl
	at org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy.toEClass(QualifyingEntityNameStrategy.java:99)
	at org.eclipse.emf.teneo.hibernate.HbDataStore.setComponentTuplizer(HbDataStore.java:633)
	at org.eclipse.emf.teneo.hibernate.HbDataStore.setTuplizer(HbDataStore.java:611)
	at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataStore(HbDataStore.java:255)
	at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:78)


In our Ecore, we don't set the instance class name. I've experimented with this and found that if I set it, then the code generation doesn't generate the interfaces. I tried modifying the ecore _after_ code generation has occurred (at which point it's still null), but I still ultimately get the same error from Teneo.

However, I've looked at the source for QualifyingEntityNameStrategy.toEClass (we're on Teneo 1.0, but it appears to be unchanged in the latest revision of the file, v1.8 ) and it appears to work by splitting the argument into the parts before and after the final dot, assigning local variables nsPrefix="com.example.newbury.impl" and eClassName="SaddleImpl". It then attempts to find an EPackage where either ePackage.getNsPrefix() or ePackage.getName() matches "com.example.newbury.impl". It won't find one, because the nsPrefix and name are both "newbury" (and the nsURI is http://example.com/newbury"). That appears to explain the exception. Prior to this, the same method is called to resolve "newbury.Horse", which of course works. In other words, this is the first call to the toEClass method that is passing a fully-qualified Java class name.

Regards,
Ben.

[Updated on: Fri, 30 November 2012 11:24]

Report message to a moderator

Re: [Teneo] Using @Embedded [message #988545 is a reply to message #988528] Fri, 30 November 2012 12:40 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Ben,
The best way to solve this probably is by implementing your own EntityNameStrategy (extending the
QualifyingEntityNameStrategy for example), see this page:
http://wiki.eclipse.org/Teneo/Hibernate/Extensions

gr. Martin

On 11/30/2012 12:24 PM, Ben Tenne wrote:
> Hi Martin,
>
> Thanks for the reply.
> Firstly, I need to correct an error in my last post. Here's the exception. The difference is that the fully qualified
> name is com.example.newbury.impl.SaddleImpl. Previously, I incorrectly put 'ordermodel' instead of 'newbury'. I'd pasted
> in the stack trace from a different run of the test, where I had the classes in a different package, thus it didn't
> match up with the Hibernate mapping.
>
>
> java.lang.IllegalArgumentException: No EClass found using com.example.newbury.impl.SaddleImpl
> at
> org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy.toEClass(QualifyingEntityNameStrategy.java:99)
> at org.eclipse.emf.teneo.hibernate.HbDataStore.setComponentTuplizer(HbDataStore.java:633)
> at org.eclipse.emf.teneo.hibernate.HbDataStore.setTuplizer(HbDataStore.java:611)
> at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataStore(HbDataStore.java:255)
> at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:78)
>
>
> In our Ecore, we don't set the instance class name. I've experimented with this and found that if I set it, then the
> code generation doesn't generate the interfaces. I tried modifying the ecore _after_ code generation has occurred (at
> which point it's still null), but I still ultimately get the same error from Teneo.
>
> However, I've looked at the source for QualifyingEntityNameStrategy.toEClass (we're on Teneo 1.0, but it appears to be
> unchanged in the latest revision of the file, v1.8 ) and it appears to work by splitting the argument into the parts
> before and after the final dot, assigning local variables nsPrefix="com.example.newbury.impl" and
> eClassName="SaddleImpl". It then attempts to find an EPackage where either ePackage.getNsPrefix() or ePackage.getName()
> matches "com.example.newbury.impl". It won't find one, because the nsPrefix and name are both "newbury" (and the nsURI
> is http://example.com/newbury"). That appears to explain the exception. Prior to this, the same method is called to
> resolve "newbury.Horse", which of course works. In other words, this is the first call to the toEClass method that is
> passing a fully-qualified Java class name.
>
> Regards,
> Simon.
>


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Using @Embedded [message #988556 is a reply to message #988545] Fri, 30 November 2012 13:55 Go to previous messageGo to next message
Ben Tenne is currently offline Ben Tenne
Messages: 49
Registered: October 2009
Member
Thanks Martin,

My Horse-to-Saddle scenario seems like the simplest form of Embedded/Embeddable use case I can think of. Therefore, does this mean that Teneo won't cope with Embedded/Embeddable at all without some degree of customization? From the documentation, I believed that it would work to some extent. Am I misunderstanding, or doing something wrong in terms of my EMF model?

Thanks,
Ben.
Re: [Teneo] Using @Embedded [message #988568 is a reply to message #988556] Fri, 30 November 2012 14:19 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Ben,
This works fine if you have an instanceclass in the eclass, this is a common case. Your approach is fine also btw, so it
is a missing feature/bug. You can enter a bugzilla for it, but it is hard to maintain previous releases very actively
without funding. So this bugzilla will likely be solved in 2.0.0.

In any case you can workaround it by implementing your own EntityNameStrategy.

gr. Martin

On 11/30/2012 02:55 PM, Ben Tenne wrote:
> Thanks Martin,
>
> My Horse-to-Saddle scenario seems like the simplest form of Embedded/Embeddable use case I can think of. Therefore,
> does this mean that Teneo won't cope with Embedded/Embeddable at all without some degree of customization? From the
> documentation, I believed that it would work to some extent. Am I misunderstanding, or doing something wrong in terms
> of my EMF model?
>
> Thanks,
> Ben.


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Using @Embedded [message #989984 is a reply to message #988344] Mon, 10 December 2012 10:41 Go to previous message
Ben Tenne is currently offline Ben Tenne
Messages: 49
Registered: October 2009
Member
I fully appreciate that it's impractical to maintain legacy releases. Being stuck on an old version is our problem and we have to live with the consequences. We've had the same scenario previously with EMF itself and have generally managed to work around this by gaining an understanding of how problems have been dealt with in the later version and retro-fit equivalent changes ourselves.

Thanks again for your help, Martin. EMF and, more recently, Teneo, have been extremely useful to us and we are very grateful for the support.

Regards,
Ben.
Previous Topic:[CDO/Hibernate] UnsupportedOperationException at ...GrowingRandomAccessList.add(...)
Next Topic:[CDO] CommitException: This transaction has conflicts
Goto Forum:
  


Current Time: Sun Sep 21 18:18:27 GMT 2014

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

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