[jboss-user] [EJB 3.0] - Re: How to get the size of a Lazy load relation
do-not-reply at jboss.com
Mon Sep 17 09:46:23 EDT 2007
Within the context of your UserTransaction (if your persistence unit has Tx type JTA) or Hibernate Session (if you're managing this manually), I'd execute an EJBQL "COUNT" Function to get a slim-and-trim resultant SQL Query sent to your DB.
Integer objId = [whatever your PK is];
| EntityManager em = [wherever you get your EM from];
| Integer count = (Integer)(em.createQuery("SELECT COUNT(obj.association) FROM " + YourEntityBean.class.getName()
| + " obj WHERE obj.id = :objId").setParameter("objId",objId).getSingleResult());
You don't really want to be "loading" anything if you don't need these objects....just the count.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4085051#4085051
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4085051
More information about the jboss-user