Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 42288 invoked from network); 23 Jul 2007 21:41:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Jul 2007 21:41:53 -0000 Received: (qmail 97361 invoked by uid 500); 23 Jul 2007 21:41:53 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 97304 invoked by uid 500); 23 Jul 2007 21:41:53 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 97281 invoked by uid 99); 23 Jul 2007 21:41:53 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2007 14:41:53 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2007 14:41:51 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 0F67271418E for ; Mon, 23 Jul 2007 14:41:31 -0700 (PDT) Message-ID: <6496351.1185226891025.JavaMail.jira@brutus> Date: Mon, 23 Jul 2007 14:41:31 -0700 (PDT) From: "Pinaki Poddar (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Created: (OPENJPA-291) Entity Relation as identity for self-referential relation breaks enhancer MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Entity Relation as identity for self-referential relation breaks enhancer ------------------------------------------------------------------------- Key: OPENJPA-291 URL: https://issues.apache.org/jira/browse/OPENJPA-291 Project: OpenJPA Issue Type: Bug Reporter: Pinaki Poddar Priority: Minor Use Case: A Node of a tree has a reference to parent node and a collection of child nodes. The complexity is how the node is identified. Instead of a simple primary identity, the node is using an identity that is composed of a primitive and its parent. OpenJPA allows parent (a uni-cardinarity relation) to be used as part of compound primary key. But the entire process of enhancement and metadata resolution do not fully cover when the relation is self-recursive. The use case of defining such a key however does not seem to be common. Anyway, consider Node of a tree defined for persistence as follows: @Entity @IdClass(Node.SelfId.class) public class Node { @Id private long id; @Id @ManyToOne private Node parent; @OneToMany(mappedBy="parent", cascade=CascadeType.ALL) private List children; public class SelfId { public long id; public SelfId parent; } 1. Enhancer breaks on Node.class Because metadata resolution goes to infinite recursive loop and a StackOverflow The codelines that breaks are in MetaDataRepository and the tentative patch shows why infinite recursion is happening by just stopping it. The impact of cutting it short is not clear/investigated. Index: openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java =================================================================== --- openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java (revision 558795) +++ openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java (working copy) @@ -552,11 +552,15 @@ // resolve relation primary key fields for mapping dependencies FieldMetaData[] fmds = meta.getDeclaredFields(); - for (int i = 0; i < fmds.length; i++) - if (fmds[i].isPrimaryKey()) + for (int i = 0; i < fmds.length; i++) { + if (fmds[i].isPrimaryKey()) { + if (fmds[i].getObjectIdFieldType(). + isAssignableFrom(meta.getDescribedType())) + continue; getMetaData(fmds[i].getDeclaredType(), meta.getEnvClassLoader(), false); - + } + } 2. This patch stops the recursion but does not solve the problem. The enhanced Node class fails to create a ApplicationId. For a simple test case such as (the test case is attached) public void testPersistTree() { OpenJPAEntityManager em = getEM(); em.begin(); Node root = new Node(1000L,null); createTree(root, new int[]{1,2,3}, 2);// 3-levels, fanout/node=2 em.persist(root); em.commit(); } <1.0.0-SNAPSHOT-SNAPSHOT nonfatal general error> org.apache.openjpa.persistence.PersistenceException: org.apache.openjpa.util.ObjectId at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2437) at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2333) at org.apache.openjpa.kernel.BrokerImpl.persistAll(BrokerImpl.java:2279) at org.apache.openjpa.kernel.SingleFieldManager.persist(SingleFieldManager.java:264) at org.apache.openjpa.kernel.StateManagerImpl.cascadePersist(StateManagerImpl.java:2741) at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2432) at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2251) at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1010) at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:541) at tree.TestTree.testPersistTree(TestTree.java:22) Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId at tree.Node.pcCopyKeyFieldsToObjectId(Node.java) at org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:386) at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2405) ... 27 more 3. How does the enhanced Node class looks like? Firstly, Java decomiler (jad) itself is confused about the same method. $ jad classes\tree\Node.class Parsing classes\tree\Node.class...Parsing inner class classes\tree\Node$SelfId.class...Overwrite Node.jad [y/n/a/s] ? y Generating Node.jad Couldn't fully decompile method pcCopyKeyFieldsToObjectId The decompiled file is attached. 4. The enhanced code is generated in PCEnhancer.addExtractObjectIdFieldValueCode() But I found the debugging the piece hard. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.