Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [TENEO] Lazy Loading with UML(Persisting UML with Teneo)
[TENEO] Lazy Loading with UML [message #990248] Tue, 11 December 2012 15:25 Go to next message
Michel Dirix is currently offline Michel DirixFriend
Messages: 2
Registered: December 2012
Junior Member
Hi,
I want to store UML model in a postgres DB using Teneo.
No problem with db configuration.

But I meet problems when I retrieve datas. For example, I create a Package, a subPackage and a Class in this subpackage.
All is persisted but when I retrieve the top package, childs are not found.

Here is my code :
public class AppTest extends TestCase {

	private SessionFactory sessionFactory;

	@Override
	protected void setUp() throws Exception {
		final Properties props = new Properties();

		props.setProperty(Environment.DRIVER, "org.postgresql.Driver");
		props.setProperty(Environment.USER, "postgres");
		props.setProperty(Environment.URL, "jdbc:postgresql://127.0.0.1:5432/teneoumllazy");
		props.setProperty(Environment.PASS, "midix");
		props.setProperty(Environment.DIALECT, org.hibernate.dialect.ProgressDialect.class.getName());
		props.setProperty("hibernate.show_sql", "true");
		props.setProperty("teneo.naming.default_id_column", "uuid");
		props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
		// props.setProperty(PersistenceOptions.FORCE_LAZY, "true");
		props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "ALL");
		String hbName = "database";
		final HbDataStore hbds = HbHelper.INSTANCE.createRegisterDataStore(hbName);

		hbds.setDataStoreProperties(props);

		hbds.setEPackages(new EPackage[] { EcorePackage.eINSTANCE, UMLPackage.eINSTANCE });

		try {
			hbds.initialize();
		} finally {
			// print the generated mapping
			// System.err.println(hbds.getMappingXML());
		}

		sessionFactory = hbds.getSessionFactory();

		Session session = sessionFactory.openSession();
		Transaction tx = session.getTransaction();
		tx.begin();
		org.eclipse.uml2.uml.Package ePackage = UMLFactory.eINSTANCE.createPackage();
		ePackage.setName("com.test");

		org.eclipse.uml2.uml.Package ePackage2 = UMLFactory.eINSTANCE.createPackage();
		ePackage2.setName("middle");
		ePackage.getPackagedElements().add(ePackage2);

		org.eclipse.uml2.uml.Class clazz = UMLFactory.eINSTANCE.createClass();
		clazz.setName("Test");

		ePackage2.getPackagedElements().add(clazz);

		session.persist(ePackage);
		tx.commit();

		session.close();
	}


	public void testApp() {
		Session session = sessionFactory.openSession();
		Transaction tx = session.getTransaction();
		tx.begin();
		Query query = session.createQuery("from Package p where name = 'com.test'");
		org.eclipse.uml2.uml.Package ePackage = (org.eclipse.uml2.uml.Package)query.uniqueResult();
		System.out.println(ePackage.getName());
		System.out.println("size : " + ePackage.getPackagedElements().size());
		session.close();
	}
}


The package name is displayed correctly but the child size is 0.

The problem is same if I uncomment props.setProperty(PersistenceOptions.FORCE_LAZY, "true");

Can someone help me?

Best regards
  • Attachment: AppTest.java
    (Size: 2.86KB, Downloaded 207 times)
Re: [TENEO] Lazy Loading with UML [message #990334 is a reply to message #990248] Tue, 11 December 2012 22:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Michel,
I tested this and the reason that this happens is because of multiple inheritance. The Package inherits from namespace,
packageableelements and templateableelement. The packageelement efeature references the packageableelements type.

However, in a rdb/orm environment, multiple inheritance is not supported fully. In this case the Package type will not
be persisted in the packageableelements table but in the namespace table. So the packageableelements table remains empty
and the packageableelements efeature does not have content.

See here for more information:
http://wiki.eclipse.org/Teneo/Hibernate/ModelRelational/Inheritance_Mapping#Multiple_Inheritance_Support

gr. Martin

On 12/11/2012 07:13 PM, Michel Dirix wrote:
> Hi,
> I want to store UML model in a postgres DB using Teneo.
> No problem with db configuration.
>
> But I meet problems when I retrieve datas. For example, I create a Package, a subPackage and a Class in this subpackage.
> All is persisted but when I retrieve the top package, childs are not found.
>
> Here is my code :
>
> public class AppTest extends TestCase {
>
> private SessionFactory sessionFactory;
>
> @Override
> protected void setUp() throws Exception {
> final Properties props = new Properties();
>
> props.setProperty(Environment.DRIVER, "org.postgresql.Driver");
> props.setProperty(Environment.USER, "postgres");
> props.setProperty(Environment.URL, "jdbc:postgresql://127.0.0.1:5432/teneoumllazy");
> props.setProperty(Environment.PASS, "midix");
> props.setProperty(Environment.DIALECT, org.hibernate.dialect.ProgressDialect.class.getName());
> props.setProperty("hibernate.show_sql", "true");
> props.setProperty("teneo.naming.default_id_column", "uuid");
> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
> // props.setProperty(PersistenceOptions.FORCE_LAZY, "true");
> props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "ALL");
> String hbName = "database";
> final HbDataStore hbds = HbHelper.INSTANCE.createRegisterDataStore(hbName);
>
> hbds.setDataStoreProperties(props);
>
> hbds.setEPackages(new EPackage[] { EcorePackage.eINSTANCE, UMLPackage.eINSTANCE });
>
> try {
> hbds.initialize();
> } finally {
> // print the generated mapping
> // System.err.println(hbds.getMappingXML());
> }
>
> sessionFactory = hbds.getSessionFactory();
>
> Session session = sessionFactory.openSession();
> Transaction tx = session.getTransaction();
> tx.begin();
> org.eclipse.uml2.uml.Package ePackage = UMLFactory.eINSTANCE.createPackage();
> ePackage.setName("com.test");
>
> org.eclipse.uml2.uml.Package ePackage2 = UMLFactory.eINSTANCE.createPackage();
> ePackage2.setName("middle");
> ePackage.getPackagedElements().add(ePackage2);
>
> org.eclipse.uml2.uml.Class clazz = UMLFactory.eINSTANCE.createClass();
> clazz.setName("Test");
>
> ePackage2.getPackagedElements().add(clazz);
>
> session.persist(ePackage);
> tx.commit();
>
> session.close();
> }
>
>
> public void testApp() {
> Session session = sessionFactory.openSession();
> Transaction tx = session.getTransaction();
> tx.begin();
> Query query = session.createQuery("from Package p where name = 'com.test'");
> org.eclipse.uml2.uml.Package ePackage = (org.eclipse.uml2.uml.Package)query.uniqueResult();
> System.out.println(ePackage.getName());
> System.out.println("size : " + ePackage.getPackagedElements().size());
> session.close();
> }
> }
>
>
> The package name is displayed correctly but the child size is 0.
>
> The problem is same if I uncomment props.setProperty(PersistenceOptions.FORCE_LAZY, "true");
>
> Can someone help me?
>
> Best regards
>


--

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] Lazy Loading with UML [message #990460 is a reply to message #990334] Wed, 12 December 2012 15:29 Go to previous messageGo to next message
Michel Dirix is currently offline Michel DirixFriend
Messages: 2
Registered: December 2012
Junior Member
Hi Martin,
Thanks for your answer.

So I have to find the good INHERITANCE_MAPPING or modify the hibernate xml file?

I tried JOINED and TABLE_PER_CLASS without success, I have errors when the xml file is loaded.

Best regards
Michel Dirix
Re: [TENEO] Lazy Loading with UML [message #990701 is a reply to message #990460] Wed, 12 December 2012 22:03 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Michael,
The solution is to influence the primary parent eclass, but you are stuck if other ereferences refer to the other super
eclasses...

It is the way orm tools work I am afraid, multiple inheritance is only supported partially.

gr. Martin

On 12/12/2012 04:29 PM, Michel Dirix wrote:
> Hi Martin,
> Thanks for your answer.
>
> So I have to find the good INHERITANCE_MAPPING or modify the hibernate xml file?
>
> I tried JOINED and TABLE_PER_CLASS without success, I have errors when the xml file is loaded.
>
> Best regards
> Michel Dirix


--

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
Previous Topic:a reference to a previous element (tree view of the model)
Next Topic:[CDO] Server replication mechanism
Goto Forum:
  


Current Time: Fri Mar 29 12:31:14 GMT 2024

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

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

Back to the top