Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] (rewritten question): Resource is empty on read, despite DB populated correctly
[Teneo] (rewritten question): Resource is empty on read, despite DB populated correctly [message #1132947] Fri, 11 October 2013 13:56 Go to next message
Nikt Zupelnie is currently offline Nikt Zupelnie
Messages: 7
Registered: October 2013
Junior Member
Hello.

I have a problem with Teneo for more advanced .ecore files.

1. Simple .ecore works

(note: some EPackage schema parts were removed and nsURI="http__ introduced due to the forum antispam error filter... grrrr.)

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage [b]NOTE: SCHEMA CONTENT REMOVED because of the "You can only use links to eclipse.org sites while you have fewer than 5 messages" forum error message (c'mon...).[/b]
  xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="example" nsURI="http___example/1.0" nsPrefix="example"> 
  <eClassifiers xsi:type="ecore:EClass" name="Entity">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="email" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
</ecore:EPackage>


I can persist this entity to/from database without problem using Teneo's Resource.


2. What doesn't work

But for this ecore:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage [b]NOTE: CONTENT REMOVED because of the "You can only use links to eclipse.org sites while you have fewer than 5 messages" forum error message (c'mon...).[/b]
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="process" nsURI="http__process/1.0" nsPrefix="process">
  <eClassifiers xsi:type="ecore:EClass" name="ProcessModel">
    <eStructuralFeatures xsi:type="ecore:EReference" name="ownedActivity" upperBound="-1"
        eType="#//Activity" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="ownedParticipant" upperBound="-1"
        eType="#//Participant" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="ownedTechnique" upperBound="-1"
        eType="#//Technique" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Activity">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="startTime" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDate"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="endTime" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDate"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="subActivity" upperBound="-1"
        eType="#//Activity" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="precedingActivity" eType="#//Activity"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="executingParticipant" upperBound="-1"
        eType="#//Participant"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="technique" upperBound="-1"
        eType="#//Technique"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="ownedRel" upperBound="-1"
        eType="#//ActivityRel" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Participant"/>
  <eClassifiers xsi:type="ecore:EEnum" name="ActivityRelKind">
    <eLiterals name="Decomposition"/>
    <eLiterals name="Precedence" value="1" literal="Precedence"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Technique"/>
  <eClassifiers xsi:type="ecore:EClass" name="Person" eSuperTypes="#//Participant">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="email" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="organization" upperBound="-1"
        eType="#//Organization"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Tool" eSuperTypes="#//Participant">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="version" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Organization" eSuperTypes="#//Participant">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="address" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="subOrganization" upperBound="-1"
        eType="#//Organization" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ActivityRel">
    <eStructuralFeatures xsi:type="ecore:EReference" name="target" lowerBound="1"
        eType="#//Activity"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="source" lowerBound="1"
        eType="#//Activity"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="#//ActivityRelKind"/>
  </eClassifiers>
</ecore:EPackage>



I succesfully initialized Teneo (the same code as in "1. What works"):

private void init(IInitializationStrategy initializationStrategy)
    {
        final Properties props = new Properties();
        initializationStrategy.initializeProperties(props);
        String hbName = "test";
        hibernateDataStore = HbHelper.INSTANCE.createRegisterDataStore(hbName);
        hibernateDataStore.setDataStoreProperties(props);
        hibernateDataStore.setAuditing(true);
        hibernateDataStore.setEPackages(getPackagesToInitialize());
        hibernateDataStore.initialize();

        String uriStr = "hibernate://?"+ HibernateResource.DS_NAME_PARAM +"="+hbName;
        final URI uri = URI.createURI(uriStr);
        ResourceSet resourceSet = new ResourceSetImpl();
        
        resource = resourceSet.getResource(uri, true);
   }


and persist an entity to it (the same code as in "1. What works"):

        Organization organization = ProcessFactory.eINSTANCE
                .createOrganization();
        organization.setAddress("resource-created organization");
        
        resource.getContents().add(organization);
        
        try {
            resource.save(null);
        } catch (IOException e) {
            e.printStackTrace();
        }        



Now I can see that database has this entity persisted. When I'm using Teneo's hibernate session to read this data I can do it without problems, but when I try to read it using Resource (after initializing it in the init() method above), the initialized resource object holds no data, so iteration on it brings nothing:

        for (EObject eObject : resource.getContents()) {
            System.out.println(eObject.toString());
        };


Why it is empty? How can I read this data using the Resource API? What are the Teneo limitations that I apparently hit for this .ecore? I think that this is Teneo-related problem because I can write/read this exactly model with replacing Teneo with XMIResourceFactoryImpl in my code and write/read to XMI without any problems.

This is just a small part of my whole domain. It contains several .ecore files and references between them (some classes extends classes from other .ecores).

[Updated on: Sat, 12 October 2013 13:59]

Report message to a moderator

Re: [Teneo] (rewritten question): Resource is empty on read, despite DB populated correctly [message #1134403 is a reply to message #1132947] Sat, 12 October 2013 13:19 Go to previous messageGo to next message
Nikt Zupelnie is currently offline Nikt Zupelnie
Messages: 7
Registered: October 2013
Junior Member
I've updated my question after performing some more research on the subject.
Re: [Teneo] (rewritten question): Resource is empty on read, despite DB populated correctly [message #1134465 is a reply to message #1134403] Sat, 12 October 2013 14:19 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Nikt,
I am not sure if I saw your updates.

See here for your question:
http://wiki.eclipse.org/Teneo/Hibernate/FAQ#The_resource_is_empty_in_the_generated_editor

As a default the resource will try to load top-level types. Or you can tell it what types to load or use a query.
In your case maybe the entity you persist is not a top-level type. So can you try loading using a query?

gr. Martin


On 10/12/2013 03:19 PM, Nikt Zupelnie wrote:
> I've updated my question after performing some more research on the subject.


--

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] (rewritten question): Resource is empty on read, despite DB populated correctly [message #1136141 is a reply to message #1134465] Sun, 13 October 2013 17:41 Go to previous message
Nikt Zupelnie is currently offline Nikt Zupelnie
Messages: 7
Registered: October 2013
Junior Member
That did the job!

Thank you Martin!

Previous Topic:[Teneo] Generate ecore model from database?
Next Topic:[EMFStore] access to EditingDomain in EMFStore
Goto Forum:
  


Current Time: Sun Oct 26 05:04:57 GMT 2014

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

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