Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Extra lazy loading(problems with add data)
Extra lazy loading [message #856346] Wed, 25 April 2012 15:26 Go to next message
Pavel Kolman is currently offline Pavel KolmanFriend
Messages: 4
Registered: April 2012
Junior Member
Hi,
I want to setup Extra lazy loading for hibernate on one sorted collection of my emf model. I use teneo mapping fot it. I used @OneToMany(fetch=EXTRA) according to eclipse/teneo/hibernate wiki. Everything was fine and my collection became HbExtraLazyPersistableEList<E> in runtime. I wanted to add some object to the collection and commit transaction to write everything to DB. But nothing happens. In DB were 0 objects in the collection.
Then I wanted to get some object from the collection and error occured. For tests I used:

Iterator<EObject> it = LazyCollectionUtils.getPagedLoadingIterator(objs, 10);
for (int i = 0; it.hasNext();) {
  EObject eObject = it.next();
  log.info("" + eObject);
  if (i++ == 100) break;
}


error was:
org.hibernate.QueryException: collection of values in filter: this [ order by workingset_content_idx]
	at org.hibernate.hql.ast.HqlSqlWalker.prepareFromClauseInputTree(HqlSqlWalker.java:250)
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:717)
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584)
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
	at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:256)
	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187)
	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:155)
......
.....


I really hope someone can help...?
Re: Extra lazy loading [message #856572 is a reply to message #856346] Wed, 25 April 2012 19:56 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Pavel,
It is difficult for me to comment on this, I guess that the objs collection is the HbExtraLazyPersistableList?

I have several test cases which test this, for example this one:
http://git.eclipse.org/c/teneo/org.eclipse.emf.teneo.git/tree/tests/org.eclipse.emf.teneo.hibernate.test/src/org/eclipse/emf/teneo/hibernate/test/emf/sample/TestLazyUtilsAction.java

Can you make a test project which reproduces your behavior? Running on hsqldb or something?

gr. Martin

On 04/25/2012 05:26 PM, Pavel Kolman wrote:
> Hi,
> I want to setup Extra lazy loading for hibernate on one sorted collection of my emf model. I use teneo mapping fot it. I
> used @OneToMany(fetch=EXTRA) according to eclipse/teneo/hibernate wiki. Everything was fine and my collection became
> HbExtraLazyPersistableEList<E> in runtime. I wanted to add some object to the collection and commit transaction to write
> everything to DB. But nothing happens. In DB were 0 objects in the collection.
> Then I wanted to get some object from the collection and error occured. For tests I used:
>
> Iterator<EObject> it = LazyCollectionUtils.getPagedLoadingIterator(objs, 10);
> for (int i = 0; it.hasNext();) {
> EObject eObject = it.next();
> log.info("" + eObject);
> if (i++ == 100) break;
> }
>
>
> error was:
> org.hibernate.QueryException: collection of values in filter: this [ order by workingset_content_idx]
> at org.hibernate.hql.ast.HqlSqlWalker.prepareFromClauseInputTree(HqlSqlWalker.java:250)
> at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:717)
> at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584)
> at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
> at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
> at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:256)
> at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187)
> at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:155)
> ......
> .....
>
>
> I really hope someone can help...?


--

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: Extra lazy loading [message #865581 is a reply to message #856572] Mon, 30 April 2012 13:19 Go to previous messageGo to next message
Pavel Kolman is currently offline Pavel KolmanFriend
Messages: 4
Registered: April 2012
Junior Member
Hello Martin,
I created test case:
line number=21: public class TestLazyLoading {

		private static int INVOICE_COUNT = 2;
		
		/** Creates an item, an address and links them to a po. 
		 * @param user */
		public void doAction(User user, Session session) {
			final WorkingSetsFactory factory = WorkingSetsFactory.eINSTANCE;
			// create a book, writer and library
			Transaction tr = session.beginTransaction();

			final WorkingSet ws = factory.createWorkingSet();
			ws.setName("Test ws");
			ws.setOwner(user);

			Invoice invoice = BillingFactory.eINSTANCE.createInvoice();
			invoice.setIid("65464");
			session.save(invoice);
			
			Invoice invoice2 = BillingFactory.eINSTANCE.createInvoice();
			invoice2.setIid("987987987");
			session.save(invoice2);
			
			ws.getContent().add(invoice);
			ws.getContent().add(invoice2);
			Serializable wsId = session.save(ws);
			tr.commit();

			assertEquals(INVOICE_COUNT, ws.getContent().size());

			tr = session.beginTransaction();
			Query query = session.createQuery("from WorkingSet ws where ws.id = :wsId");
			query.setParameter("wsId", wsId);
			
			List resultList = query.list();
			WorkingSet wsFromQuery = (WorkingSet) resultList.get(0);
			
			testLazySize(wsFromQuery.getContent());
			
			assertTrue(((Invoice) wsFromQuery.getContent().get(0)).getIid().compareTo("65464") == 0);
			tr.commit();
		
			tr = session.beginTransaction();
			WorkingSet loadedWs = ws;
			session.refresh(loadedWs);
			
			loadedWs.getContent().clear();
			
			// create and store a INVOICE_COUNT books
			for (int i = 0; i < INVOICE_COUNT; i++) {
				final Invoice inv = BillingFactory.eINSTANCE.createInvoice();
				inv.setIid("" + (i* 13));
				session.save(inv);
				ws.getContent().add(inv);
			}
			tr.commit();
			
			tr = session.beginTransaction();
			session.refresh(loadedWs);
			
			final Iterator<EObject> invoices = LazyCollectionUtils.getPagedLoadingIterator(loadedWs.getContent(), 1);
			int bkCount = 0;
			while (invoices.hasNext()) {
				final Invoice iv = (Invoice) invoices.next();
				assertEquals("" + (bkCount * 13), iv.getIid());
				bkCount++;
			}
			checkIsStillLazy(loadedWs.getContent());
			assertEquals(INVOICE_COUNT, bkCount);
		}

		private void assertEquals(String string, String string2) {
			if (!string.equals(string2)) throw new IllegalStateException("Error while input parameters '" + string + "' and '" + string2 + "' is not equal!!");
		}

		private void assertEquals(int i, int size) {
			if (i != size) throw new IllegalStateException("Error while " + i + " != " + size + "!!");
		}

		protected void testLazySize(List<?> list) {
			final PersistableEList<?> persistableEList = (PersistableEList<?>)list;
			final PersistentCollection persistentCollection = (PersistentCollection)persistableEList.getDelegate();
			assertFalse(persistentCollection.wasInitialized());
			assertFalse(persistableEList.isLoaded());
			int size = LazyCollectionUtils.size(list);
			assertTrue(size > 0);
			assertFalse(persistentCollection.wasInitialized());
			assertFalse(persistableEList.isLoaded());
		}

		private void assertTrue(boolean condition) {
			if (!condition) throw new IllegalStateException("Error while condition is not true!!");
		}

		private void assertFalse(boolean wasInitialized) {
			assertTrue(!wasInitialized);
		}

		protected void checkIsStillLazy(List<?> list) {
			final PersistableEList<?> persistableEList = (PersistableEList<?>)list;
			final PersistentCollection persistentCollection = (PersistentCollection)persistableEList.getDelegate();
			assertFalse(persistentCollection.wasInitialized());
			assertFalse(persistableEList.isLoaded());
		}
}


Result of this test case was:
java.lang.ClassCastException: org.eclipse.emf.ecore.util.EObjectResolvingEList cannot be cast to org.eclipse.emf.teneo.mapping.elist.PersistableEList
	at com.mediasol.contract.testing.servlets.test.TestLazyLoading.testLazySize(TestLazyLoading.java:101)
	at com.mediasol.contract.testing.servlets.test.TestLazyLoading.doAction(TestLazyLoading.java:58)
	at com.mediasol.contract.testing.servlets.test.TestServlet.doGet(TestServlet.java:67)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
	at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
	at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
	at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
	at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
...
...
...


If I load some another Working set from DB it is instance of HbExtraLazyPersistableList. When I execute my test case, create new WorkingSet and add something into its content I get instance of EObjectResolvingEList as content field type. Is this normal??

Thanks
Best regards
Pavel Kolman
Re: Extra lazy loading [message #865597 is a reply to message #865581] Mon, 30 April 2012 13:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Pavel,
I am not sure on which line in your test it fails. But it is true that the list implementation is different for new
objects compared to objects loaded from the db. Only objects loaded from the db will have an extra-lazy loaded list.
(but not sure if you mean that)

gr. Martin

On 04/30/2012 03:19 PM, Pavel Kolman wrote:
> Hello Martin,
> I created test case:
>
> line number=21: public class TestLazyLoading {
>
> private static int INVOICE_COUNT = 2;
>
> /** Creates an item, an address and links them to a po. * @param user */
> public void doAction(User user, Session session) {
> final WorkingSetsFactory factory = WorkingSetsFactory.eINSTANCE;
> // create a book, writer and library
> Transaction tr = session.beginTransaction();
>
> final WorkingSet ws = factory.createWorkingSet();
> ws.setName("Test ws");
> ws.setOwner(user);
>
> Invoice invoice = BillingFactory.eINSTANCE.createInvoice();
> invoice.setIid("65464");
> session.save(invoice);
>
> Invoice invoice2 = BillingFactory.eINSTANCE.createInvoice();
> invoice2.setIid("987987987");
> session.save(invoice2);
>
> ws.getContent().add(invoice);
> ws.getContent().add(invoice2);
> Serializable wsId = session.save(ws);
> tr.commit();
>
> assertEquals(INVOICE_COUNT, ws.getContent().size());
>
> tr = session.beginTransaction();
> Query query = session.createQuery("from WorkingSet ws where ws.id = :wsId");
> query.setParameter("wsId", wsId);
>
> List resultList = query.list();
> WorkingSet wsFromQuery = (WorkingSet) resultList.get(0);
>
> testLazySize(wsFromQuery.getContent());
>
> assertTrue(((Invoice) wsFromQuery.getContent().get(0)).getIid().compareTo("65464") == 0);
> tr.commit();
>
> tr = session.beginTransaction();
> WorkingSet loadedWs = ws;
> session.refresh(loadedWs);
>
> loadedWs.getContent().clear();
>
> // create and store a INVOICE_COUNT books
> for (int i = 0; i < INVOICE_COUNT; i++) {
> final Invoice inv = BillingFactory.eINSTANCE.createInvoice();
> inv.setIid("" + (i* 13));
> session.save(inv);
> ws.getContent().add(inv);
> }
> tr.commit();
>
> tr = session.beginTransaction();
> session.refresh(loadedWs);
>
> final Iterator<EObject> invoices = LazyCollectionUtils.getPagedLoadingIterator(loadedWs.getContent(), 1);
> int bkCount = 0;
> while (invoices.hasNext()) {
> final Invoice iv = (Invoice) invoices.next();
> assertEquals("" + (bkCount * 13), iv.getIid());
> bkCount++;
> }
> checkIsStillLazy(loadedWs.getContent());
> assertEquals(INVOICE_COUNT, bkCount);
> }
>
> private void assertEquals(String string, String string2) {
> if (!string.equals(string2)) throw new IllegalStateException("Error while input parameters '" + string + "' and '" +
> string2 + "' is not equal!!");
> }
>
> private void assertEquals(int i, int size) {
> if (i != size) throw new IllegalStateException("Error while " + i + " != " + size + "!!");
> }
>
> protected void testLazySize(List<?> list) {
> final PersistableEList<?> persistableEList = (PersistableEList<?>)list;
> final PersistentCollection persistentCollection = (PersistentCollection)persistableEList.getDelegate();
> assertFalse(persistentCollection.wasInitialized());
> assertFalse(persistableEList.isLoaded());
> int size = LazyCollectionUtils.size(list);
> assertTrue(size > 0);
> assertFalse(persistentCollection.wasInitialized());
> assertFalse(persistableEList.isLoaded());
> }
>
> private void assertTrue(boolean condition) {
> if (!condition) throw new IllegalStateException("Error while condition is not true!!");
> }
>
> private void assertFalse(boolean wasInitialized) {
> assertTrue(!wasInitialized);
> }
>
> protected void checkIsStillLazy(List<?> list) {
> final PersistableEList<?> persistableEList = (PersistableEList<?>)list;
> final PersistentCollection persistentCollection = (PersistentCollection)persistableEList.getDelegate();
> assertFalse(persistentCollection.wasInitialized());
> assertFalse(persistableEList.isLoaded());
> }
> }
>
>
> Result of this test case was:
>
> java.lang.ClassCastException: org.eclipse.emf.ecore.util.EObjectResolvingEList cannot be cast to
> org.eclipse.emf.teneo.mapping.elist.PersistableEList
> at com.mediasol.contract.testing.servlets.test.TestLazyLoading.testLazySize(TestLazyLoading.java:101)
> at com.mediasol.contract.testing.servlets.test.TestLazyLoading.doAction(TestLazyLoading.java:58)
> at com.mediasol.contract.testing.servlets.test.TestServlet.doGet(TestServlet.java:67)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
> at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
> at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
> at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> ...
> ...
> ...
>
>
> If I load some another Working set from DB it is instance of HbExtraLazyPersistableList. When I execute my test case,
> create new WorkingSet and add something into its content I get instance of EObjectResolvingEList as content field type.
> Is this normal??
> Thanks
> Best regards
> Pavel Kolman


--

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: Extra lazy loading [message #865615 is a reply to message #865581] Mon, 30 April 2012 13:40 Go to previous messageGo to next message
Pavel Kolman is currently offline Pavel KolmanFriend
Messages: 4
Registered: April 2012
Junior Member
Hi Martin,
I have some another working sets in DB. They are created by old API without enabled extra lazy loading. If I load from DB some of them, content field on loaded working set is instance of HbExtraLazyPersistableList. I invoke method testLazySize on this HbExtraLazyPersistableList and error occure! Error says that input list was initialized...

Do you know what is wrong?

Best regards
Pavel Kolman

[Updated on: Mon, 30 April 2012 13:43]

Report message to a moderator

Re: Extra lazy loading [message #865708 is a reply to message #865615] Mon, 30 April 2012 14:29 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
What error occurs where? In the previous post you mentioned you get a CCE because the list is a EObjectResolvingEList,
but now it is a HbExtraLazyPersistableList?

If you can create a test plugin project which can replicate the issue then I can take a look at that also.

gr. Martin

On 04/30/2012 03:40 PM, Pavel Kolman wrote:
> I hava some another working sets in DB. They are created by old API without enabled extra lazy loading. If I load from
> DB some of them, content field on loaded working set is instance of HbExtraLazyPersistableList. I invoke method
> testLazySize on this HbExtraLazyPersistableList and error occure! Error says that input list was initialized...
>
> Do you know what is wrong?
>
> Best regards Pavel Kolman


--

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: Extra lazy loading [message #865728 is a reply to message #865708] Mon, 30 April 2012 14:42 Go to previous messageGo to next message
Pavel Kolman is currently offline Pavel KolmanFriend
Messages: 4
Registered: April 2012
Junior Member
Hi Martin,
I have some working sets (WS) in DB. There are "old" (created by old API) and new (created with extra lazy loading = enable). If I want to query "old" WS from DB, I get HbExtraLazyPersistableList. If I want query "new" WS from DB, I get EObjectResolvingEList.

If I query some "old" WS from DB and put it as input parameter into testLazySize method then assertion error occures. Assertion error thrown from line: "assertFalse(persistentCollection.wasInitialized());" because input list was initialized.

Sorry but I can't extract one plugin from my project, because it is very big project with a lot of dependencies etc :-/

Best regards
Pavel
Re: Extra lazy loading [message #866160 is a reply to message #865728] Mon, 30 April 2012 19:19 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Pavel,
Hmm, it is somewhat difficult for me to comment on this. The extra lazy behavior which is implemented in the server/java
side and does not influence the actual db mapping. So it seems strange that old and new have different behavior. When
you mean new, I guess that you mean in a new transaction/session:
session.beginTransaction();
session.save(newRecord);
session.commitTransaction();
session.close();
session = getANewSession();
session.beginTransaction();
// readobject
// does it have an extra lazy list?

gr. Martin

On 04/30/2012 04:42 PM, Pavel Kolman wrote:
> Hi Martin,
> I have some working sets (WS) in DB. There are "old" (created by old API) and new (created with extra lazy loading =
> enable). If I want to query "old" WS from DB, I get HbExtraLazyPersistableList. If I want query "new" WS from DB, I get
> EObjectResolvingEList.
>
> If I query some "old" WS from DB and put it as input parameter into testLazySize method then assertion error occures.
> Assertion error thrown from line: "assertFalse(persistentCollection.wasInitialized());" because input list was initialized.
> Sorry but I can't extract one plugin from my project, because it is very big project with a lot of dependencies etc :-/
>
> Best regards Pavel


--

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:Texo: problem when attribute is called class
Next Topic:[DAWN] graphiti diagram editor
Goto Forum:
  


Current Time: Fri Apr 26 01:19:56 GMT 2024

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

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

Back to the top