Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3A91DBD7 for ; Mon, 24 Sep 2012 15:29:22 +0000 (UTC) Received: (qmail 90959 invoked by uid 500); 24 Sep 2012 15:29:22 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 90860 invoked by uid 500); 24 Sep 2012 15:29:22 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Delivered-To: moderator for users@openjpa.apache.org Received: (qmail 29927 invoked by uid 99); 24 Sep 2012 14:48:38 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of chris-pro@gmx.net designates 213.165.64.22 as permitted sender) Content-Type: text/plain; charset="utf-8" Date: Mon, 24 Sep 2012 16:48:07 +0200 From: "Chris Pro" Message-ID: <20120924144807.229960@gmx.net> MIME-Version: 1.0 Subject: Bi-Directional Relation and Lazy To: users@openjpa.apache.org X-Authenticated: #34947360 X-Flags: 0001 X-Mailer: WWW-Mail 6100 (Global Message Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX1/yRpAC8tvyyg3PI0jqXBrVhwdJQeMzEBMYb6mGt+ LQYUbl2Rfu700DN5Ea5kyPzWBM4qrzQMOqCw== Content-Transfer-Encoding: 8bit X-GMX-UID: 8BcScLA4eSEqREEifnYhYoN+IGRvb8BU X-Virus-Checked: Checked by ClamAV on apache.org Hello I've two JPA-Entities (OpenJPA 2.2.0): Task and TaskState. TaskState have a foreign key on Task. Therefore I marked the relation TaskState.getTask() as Lazy. The relation opposite Task.getTaskState() is Lazy too (Default for OneToMany). So when I write a JPQL like that in an EJB both relations are filled: SELECT t FROM Task t LEFT JOIN FETCH t.TaskState With that query both relations are filled. But the relation TaskState.getTask() should be lazy and not filled. The problem is, that that query result-list-object is very big, because of the bi-directional: Task have x TaksState -> TaskState have the Task -> Task have x TaksState -> and so one. Is there a way, to prevent the loading/filling of TaskState.getTask()? Would be great, if someone could help me. @Entity public class Task implements Serializable { private static final long serialVersionUID = 1L; public Task() {} // ... private List TaskState; @OneToMany(mappedBy = "task") public List getTaskState() { return TaskState; } public void setTaskState(final List TaskState) { this.TaskState = TaskState; } } @Entity public class TaskState implements Serializable, Comparable { private static final long serialVersionUID = 1L; public TaskState() {} private Task task; @ManyToOne(fetch = FetchType.LAZY) @javax.persistence.JoinColumn(name = "state_task_Id", referencedColumnName = "task_Id", nullable = false) public Task getTask() { return task; } public void setTask(final Task task) { this.task = task; } } // EJB public Collection findAllTasks() throws BBException { try { Query query = em.createQuery("SELECT t FROM Task t LEFT JOIN FETCH t.TaskState"); Collection tasks = query.getResultList(); return tasks; // Why are the tasks on TaskState.getTaskState() are also filled with Tasks-Objects? } catch (Exception ex) { throw new BBException(ex); } }