openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From killbulle <marco.go...@gmail.com>
Subject Re: Fetch Plan ands collections mapped
Date Thu, 22 Jul 2010 09:49:06 GMT

I still got a problem

It work with a query but not with a find.

Code:

		1: EntityTransaction transaction = em.getTransaction();
		2: transaction.begin();

		3: OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
		
		4: FetchPlan fetchPlan = kem.getFetchPlan();
		5: fetchPlan.removeFetchGroup(FetchGroup.NAME_DEFAULT);
		6: fetchPlan.clearFetchGroups();
		7: fetchPlan.clearFields();
		
		8: fetchPlan.addField(AbstractCustomer.class, "name");
		
		9: fetchPlan.addField(Order.class, "status");
		
		10: OpenJPAQuery q = OpenJPAPersistence
				.cast(kem
						.createQuery("SELECT c FROM AbstractCustomer c WHERE
c.customerId=:a"));

		11: q.setParameter(1, 2);
		
		12: AbstractCustomer customer1 = (AbstractCustomer) q.getSingleResult();
		
		
		13: AbstractCustomer customer2 = kem.find(AbstractCustomer.class, 2);
		
		14: System.out.println(customer1.getName());
		15: System.out.println(customer2.getName());
		
		16: transaction.rollback();
		17: em.close();

Output:

32  pie-db-JAVA-SE  INFO   [main] openjpa.Runtime - Starting OpenJPA 1.2.2
829  pie-db-JAVA-SE  TRACE  [main] openjpa.jdbc.SQL - <t 21565531, conn
30463067> executing prepstmnt 25709120 SELECT t0.CUSTOMER_ID, t0.type,
t0.name FROM APP.CUSTOMER t0 WHERE (t0.CUSTOMER_ID = ?) [params=(int) 2]
844  pie-db-JAVA-SE  TRACE  [main] openjpa.jdbc.SQL - <t 21565531, conn
30463067> [15 ms] spent
891  pie-db-JAVA-SE  TRACE  [main] openjpa.jdbc.SQL - <t 21565531, conn
10520143> executing prepstmnt 30620267 SELECT t1.ORDER_ID, t1.status,
t1.total, t0.RESIDENTIAL_FREQUENT_CUSTOMER, t0.RESIDENTIAL_HOUSEHOLD_SIZE
FROM APP.CUSTOMER t0 LEFT OUTER JOIN APP.ORDERS t1 ON t0.OPEN_ORDER =
t1.ORDER_ID WHERE t0.CUSTOMER_ID = ? [params=(int) 2]
Roland Barcia
Roland Barcia
891  pie-db-JAVA-SE  TRACE  [main] openjpa.jdbc.SQL - <t 21565531, conn
10520143> [0 ms] spent



And if I comment the line 8 : fetchPlan.addField(AbstractCustomer.class,
"name");
The value of the line 14 is null



Can you help me ?
Thanks

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Fetch-Plan-ands-collections-mapped-tp5321552p5324711.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message