Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Strange behaviour when switching EntityNameStrategy(EntityInterfaceNameStrategy gives No annotated model element present error)
[Teneo] Strange behaviour when switching EntityNameStrategy [message #1007949] Fri, 08 February 2013 12:11 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Sorry to keep asking questions - I do try to hunt arround to find answers and debug problems myself, but I'm a bit at a loss with this one. As always, the example that follows is a much simplified version as to what the real code we have does. (I understand that as the code looks, no-one would really do this - but the case we have, it sort of occurs like this).

It is more on the EntityNameStrategy, if I run the following code using the QualifyingEntityNameStrategy then it will work OK and generates the Hibernate mapping as expected.

public class RobTest extends TestCase
{
	private Class	useThisEntityNameStrategy	= EntityInterfaceNameStrategy.class;

	//	private Class useThisEntityNameStrategy = QualifyingEntityNameStrategy.class;

	public void test1() throws Exception
	{
		EPackage.Registry.INSTANCE.put(OrdermodelPackage.eNS_URI, OrdermodelPackage.eINSTANCE);
		EPackage.Registry.INSTANCE.put(NestedPackage.eNS_URI, NestedPackage.eINSTANCE);
		EPackage.Registry.INSTANCE.put(GdcompPackage.eNS_URI, GdcompPackage.eINSTANCE);

		// First Case
		HbDataStore hbDataStore = HbHelper.INSTANCE.createRegisterDataStore("TempDataStore");

		final ExtensionManager extensionManager = hbDataStore.getExtensionManager();
		extensionManager.registerExtension(EntityNameStrategy.class.getName(), useThisEntityNameStrategy.getName());

		String mapping = null;
		try
		{
			mapping = HbHelper.INSTANCE.generateMapping(new EPackage[]{OrdermodelPackage.eINSTANCE},
					hbDataStore.getProperties(), extensionManager);
		}
		catch (Exception e)
		{
			throw e;
		}

		// Second Case
		HbDataStore hbDataStore2 = HbHelper.INSTANCE.createRegisterDataStore("TempDataStore");

		final ExtensionManager extensionManager2 = hbDataStore2.getExtensionManager();
		extensionManager2.registerExtension(EntityNameStrategy.class.getName(), useThisEntityNameStrategy.getName());

		String mapping2 = null;
		try
		{
			mapping2 = HbHelper.INSTANCE.generateMapping(new EPackage[]{GdcompPackage.eINSTANCE,
					NestedPackage.eINSTANCE}, hbDataStore2.getProperties(), extensionManager2);
		}
		catch (Exception e)
		{
			throw e;
		}

		System.out.println("First Mapping:" + mapping);
		System.out.println("Second Mapping:" + mapping2);
	}
}


However, if I switch the EntityNameStrategy to instead use EntityInterfaceNameStrategy, then when it does the second call to HbHelper.INSTANCE.generateMapping() I get an exception thrown:

java.lang.IllegalArgumentException: No annotated model element present  for: Wheel for type EClass has its epackage been registered with Teneo?
	at org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedModelImpl.checkAnnotatedPresent(PAnnotatedModelImpl.java:347)
	at org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedModelImpl.getPAnnotated(PAnnotatedModelImpl.java:289)
	at org.eclipse.emf.teneo.mapping.strategy.impl.EntityInterfaceNameStrategy.toEntityName(EntityInterfaceNameStrategy.java:84)
	at org.eclipse.emf.teneo.mapping.strategy.StrategyUtil.getEntityName(StrategyUtil.java:63)
	at org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy.getEntityName(ClassicSQLNameStrategy.java:392)
	at org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy.getForeignKeyName(ClassicSQLNameStrategy.java:110)
	at org.eclipse.emf.teneo.annotations.mapper.BaseEFeatureAnnotator.createFK(BaseEFeatureAnnotator.java:64)
	at org.eclipse.emf.teneo.annotations.mapper.OneToOneReferenceAnnotator.annotate(OneToOneReferenceAnnotator.java:99)
	at org.eclipse.emf.teneo.hibernate.annotations.HbOneToOneReferenceAnnotator.annotate(HbOneToOneReferenceAnnotator.java:48)
	at org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator.annotate(EFeatureAnnotator.java:197)
	at org.eclipse.emf.teneo.annotations.mapper.EClassAnnotator.annotate(EClassAnnotator.java:242)
	at org.eclipse.emf.teneo.hibernate.annotations.HbEClassAnnotator.annotate(HbEClassAnnotator.java:55)
	at org.eclipse.emf.teneo.annotations.mapper.EClassAnnotator.annotate(EClassAnnotator.java:101)
	at org.eclipse.emf.teneo.hibernate.annotations.HbEClassAnnotator.annotate(HbEClassAnnotator.java:55)
	at org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator.processPackage(AnnotationGenerator.java:167)
	at org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator.map(AnnotationGenerator.java:135)
	at org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingBuilder.buildMapping(PersistenceMappingBuilder.java:159)
	at org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingBuilder.buildMapping(PersistenceMappingBuilder.java:71)
	at org.eclipse.emf.teneo.hibernate.HbHelper.generateMapping(HbHelper.java:197)


I have attached a copy of the test program - from the testing that I have done - you can use pretty much any set of eCores to reproduce this one (as long as the 2 eCores are different).

It has really got me a little stumped why changing the EntityNameStrategy would have such an impact on this.

My investigation has shown up that if I change the HbHelper.INSTANCE.createRegisterDataStore() call to take different strings - then the problem goes away - however that would be a little tricky for us - and it still seems strange that changing the EntityNameStrategy would cause this problem in the first place.

I would love to have your expert advice on this one please Martin.

Thanks

Rob
  • Attachment: RobTest.java
    (Size: 2.40KB, Downloaded 310 times)
Re: [Teneo] Strange behaviour when switching EntityNameStrategy [message #1008276 is a reply to message #1007949] Sun, 10 February 2013 22:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rob,
Can you send me example ecores for which this fails? Note that if you pass in TempDataStore to both calls to HbHelper,
then the second call will return the same instance as the first call.

gr. Martin

On 02/08/2013 01:11 PM, Rob Mising name wrote:
> Hi Martin,
>
> Sorry to keep asking questions - I do try to hunt arround to find answers and debug problems myself, but I'm a bit at a loss with this one. As always, the example that follows is a much simplified version as to what the real code we have does. (I understand that as the code looks, no-one would really do this - but the case we have, it sort of occurs like this).
>
> It is more on the EntityNameStrategy, if I run the following code using the QualifyingEntityNameStrategy then it will work OK and generates the Hibernate mapping as expected.
>
> public class RobTest extends TestCase
> {
> private Class useThisEntityNameStrategy = EntityInterfaceNameStrategy.class;
>
> // private Class useThisEntityNameStrategy = QualifyingEntityNameStrategy.class;
>
> public void test1() throws Exception
> {
> EPackage.Registry.INSTANCE.put(OrdermodelPackage.eNS_URI, OrdermodelPackage.eINSTANCE);
> EPackage.Registry.INSTANCE.put(NestedPackage.eNS_URI, NestedPackage.eINSTANCE);
> EPackage.Registry.INSTANCE.put(GdcompPackage.eNS_URI, GdcompPackage.eINSTANCE);
>
> // First Case
> HbDataStore hbDataStore = HbHelper.INSTANCE.createRegisterDataStore("TempDataStore");
>
> final ExtensionManager extensionManager = hbDataStore.getExtensionManager();
> extensionManager.registerExtension(EntityNameStrategy.class.getName(), useThisEntityNameStrategy.getName());
>
> String mapping = null;
> try
> {
> mapping = HbHelper.INSTANCE.generateMapping(new EPackage[]{OrdermodelPackage.eINSTANCE},
> hbDataStore.getProperties(), extensionManager);
> }
> catch (Exception e)
> {
> throw e;
> }
>
> // Second Case
> HbDataStore hbDataStore2 = HbHelper.INSTANCE.createRegisterDataStore("TempDataStore");
>
> final ExtensionManager extensionManager2 = hbDataStore2.getExtensionManager();
> extensionManager2.registerExtension(EntityNameStrategy.class.getName(), useThisEntityNameStrategy.getName());
>
> String mapping2 = null;
> try
> {
> mapping2 = HbHelper.INSTANCE.generateMapping(new EPackage[]{GdcompPackage.eINSTANCE,
> NestedPackage.eINSTANCE}, hbDataStore2.getProperties(), extensionManager2);
> }
> catch (Exception e)
> {
> throw e;
> }
>
> System.out.println("First Mapping:" + mapping);
> System.out.println("Second Mapping:" + mapping2);
> }
> }
>
> However, if I switch the EntityNameStrategy to instead use EntityInterfaceNameStrategy, then when it does the second call to HbHelper.INSTANCE.generateMapping() I get an exception thrown:
>
> java.lang.IllegalArgumentException: No annotated model element present for: Wheel for type EClass has its epackage been registered with Teneo?
> at org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedModelImpl.checkAnnotatedPresent(PAnnotatedModelImpl.java:347)
> at org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedModelImpl.getPAnnotated(PAnnotatedModelImpl.java:289)
> at org.eclipse.emf.teneo.mapping.strategy.impl.EntityInterfaceNameStrategy.toEntityName(EntityInterfaceNameStrategy.java:84)
> at org.eclipse.emf.teneo.mapping.strategy.StrategyUtil.getEntityName(StrategyUtil.java:63)
> at org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy.getEntityName(ClassicSQLNameStrategy.java:392)
> at org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy.getForeignKeyName(ClassicSQLNameStrategy.java:110)
> at org.eclipse.emf.teneo.annotations.mapper.BaseEFeatureAnnotator.createFK(BaseEFeatureAnnotator.java:64)
> at org.eclipse.emf.teneo.annotations.mapper.OneToOneReferenceAnnotator.annotate(OneToOneReferenceAnnotator.java:99)
> at org.eclipse.emf.teneo.hibernate.annotations.HbOneToOneReferenceAnnotator.annotate(HbOneToOneReferenceAnnotator.java:48)
> at org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator.annotate(EFeatureAnnotator.java:197)
> at org.eclipse.emf.teneo.annotations.mapper.EClassAnnotator.annotate(EClassAnnotator.java:242)
> at org.eclipse.emf.teneo.hibernate.annotations.HbEClassAnnotator.annotate(HbEClassAnnotator.java:55)
> at org.eclipse.emf.teneo.annotations.mapper.EClassAnnotator.annotate(EClassAnnotator.java:101)
> at org.eclipse.emf.teneo.hibernate.annotations.HbEClassAnnotator.annotate(HbEClassAnnotator.java:55)
> at org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator.processPackage(AnnotationGenerator.java:167)
> at org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator.map(AnnotationGenerator.java:135)
> at org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingBuilder.buildMapping(PersistenceMappingBuilder.java:159)
> at org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingBuilder.buildMapping(PersistenceMappingBuilder.java:71)
> at org.eclipse.emf.teneo.hibernate.HbHelper.generateMapping(HbHelper.java:197)
>
>
> I have attached a copy of the test program - from the testing that I have done - you can use pretty much any set of eCores to reproduce this one (as long as the 2 eCores are different).
>
> It has really got me a little stumped why changing the EntityNameStrategy would have such an impact on this.
>
> My investigation has shown up that if I change the HbHelper.INSTANCE.createRegisterDataStore() call to take different strings - then the problem goes away - however that would be a little tricky for us - and it still seems strange that changing the EntityNameStrategy would cause this problem in the first place.
>
> I would love to have your expert advice on this one please Martin.
>
> Thanks
>
> Rob
>


--

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] Strange behaviour when switching EntityNameStrategy [message #1008413 is a reply to message #1008276] Tue, 12 February 2013 11:53 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Sorry for the delay - eCore files attached.

Thanks

Rob
Re: [Teneo] Strange behaviour when switching EntityNameStrategy [message #1011071 is a reply to message #1008413] Mon, 18 February 2013 19:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rob,
I did some testing with your models and testcase.

The reason that this fails is that the hbDataStore2 is the same instance as the hbDataStore (as the same name is used to
register it). So the extensionmanager is the same and the EntityNameStrategy instance is therefore also the same.

The EntityInterfaceNameStrategy class caches the internal annotated model, but in the second pass a different annotated
model is being used, however the EntityInterfaceNameStrategy still has hold of the old annotated model, resulting in
invalid cache searches.

A solution is to use a different name for the second retrieval of the datastore:
HbDataStore hbDataStore2 = HbHelper.INSTANCE.createRegisterDataStore("TempDataStore2");

Or maybe clear the internal cache somehow, but it all seems somewhat theoretical.

At least now you know why it fails and how this can be prevented.

gr. Martin

On 02/12/2013 12:53 PM, Rob Mising name wrote:
> Hi Martin,
>
> Sorry for the delay - eCore files attached.
>
> Thanks
>
> Rob
>


--

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] Strange behaviour when switching EntityNameStrategy [message #1015601 is a reply to message #1011071] Fri, 01 March 2013 10:43 Go to previous message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Thank you for the analysis and description - I think I will look at making them unique.

Thanks, Rob
(Sorry for the delay in thanking you - I have been away for a couple of weeks)
Previous Topic:[Teneo] Entity JPA Annotation Issue
Next Topic:Very odd issue with multiple schemaLocations
Goto Forum:
  


Current Time: Thu Apr 18 23:12:01 GMT 2024

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

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

Back to the top