[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - @OneToOne and SELECT (1+n) problem

Lupson do-not-reply at jboss.com
Thu Apr 3 04:51:46 EDT 2008


Lots of searching in various resources havn't solved this issue for me so here goes..:

Environment:
JBoss 4.0.5.GA
Seam 1.2.1
Oracle 10 running ojdbc14.jar

Basically, I have two entities, let's call them PERSON and PERSON_METADATA. They have a bi-directional @OneToOne relation.

Problem: I have 1000 PERSONs and I issue a JPA/HQL query such as: entityManager.createQuery("SELECT p FROM Person p").getResultList();

Looking at the SQL debug output in the log, this simple JPA query performs 1001 SELECTs instead of performing a JOIN (or LEFT JOIN if optional=true).

I've fiddled around with various FetchType.EAGER/LAZY, @LazyToOne, @Fetch(FetchMode.EAGER) etc. settings, but still I always get this 1+n number of queries, regardless of how I annotate the @OneToOne relation.

Any ideas on how to get JPA/Hibernate to EAGER load this using a single JOIN?

Thanks!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141205#4141205

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141205



More information about the jboss-user mailing list