openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1397306 - in /openjpa/branches/2.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/ ope...
Date Thu, 11 Oct 2012 20:58:20 GMT
Author: jgrassel
Date: Thu Oct 11 20:58:20 2012
New Revision: 1397306

URL: http://svn.apache.org/viewvc?rev=1397306&view=rev
Log:
OPENJPA-2233: Failed to invoke pcGetIDOwningClass method on embeddable entity with ID annotation

Added:
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestEmbeddableEntityWithIDAnnotation.java
  (with props)
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/EmbeddableEntityWithIDAnnotation.java
  (with props)
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/IDOwningClassTestEntity.java
  (with props)
Modified:
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
    openjpa/branches/2.1.x/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=1397306&r1=1397305&r2=1397306&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
Thu Oct 11 20:58:20 2012
@@ -1177,6 +1177,11 @@ public class PCEnhancer { 
             if (_meta.hasAbstractPKField() == true) { 
                 addGetIDOwningClass();
             }
+            
+            if (_meta.isEmbeddedOnly() && _meta.getIdentityType() == ClassMetaData.ID_APPLICATION)
{
+                _log.error(_loc.get("ID-field-in-embeddable-unsupported", _meta.toString()));
+            }
+            
             addNewObjectIdInstanceMethod(true);
             addNewObjectIdInstanceMethod(false);
         }
@@ -2609,13 +2614,12 @@ public class PCEnhancer { 
         // new <oid class> ();
         code.anew().setType(oidType);
         code.dup();
-        if (_meta.isOpenJPAIdentity() || (obj && usesClsString ==
-                    Boolean.TRUE)) {
-            if(_meta.isEmbeddedOnly() || _meta.hasAbstractPKField() == true ) {
+        if (_meta.isOpenJPAIdentity() || (obj && usesClsString == Boolean.TRUE))
{
+            if ((_meta.isEmbeddedOnly() && ! (_meta.getIdentityType() == ClassMetaData.ID_APPLICATION))

+                || _meta.hasAbstractPKField() == true ) {
                 code.aload().setThis();
-                code.invokevirtual().setMethod(PRE + "GetIDOwningClass",
-                    Class.class, null);
-            }else {
+                code.invokevirtual().setMethod(PRE + "GetIDOwningClass", Class.class, null);
+            } else {
                 code.classconstant().setClass(getType(_meta));
             }
         }

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties?rev=1397306&r1=1397305&r2=1397306&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
Thu Oct 11 20:58:20 2012
@@ -216,5 +216,6 @@ get-field: Error while getting value of 
 get-method: Error while getting value by getter method {1} on instance {0} by reflection.
   
 set-field: Error while setting value {2} of {3} on field {1} of instance {0} by reflection.
   
 set-method: Error while setting value {2} of {3} by setter method {1} of instance {0} by
reflection.
+ID-field-in-embeddable-unsupported: The identity field defined in the {0} Embeddable is not
supported.
 down-level-enhanced-entity: The Entity "{0}" was enhanced at level "{1}", but the current
level of enhancement is \
 "{2}". 

Added: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestEmbeddableEntityWithIDAnnotation.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestEmbeddableEntityWithIDAnnotation.java?rev=1397306&view=auto
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestEmbeddableEntityWithIDAnnotation.java
(added)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestEmbeddableEntityWithIDAnnotation.java
Thu Oct 11 20:58:20 2012
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.openjpa.persistence.enhance;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.enhance.common.apps.EmbeddableEntityWithIDAnnotation;
+import org.apache.openjpa.persistence.enhance.common.apps.IDOwningClassTestEntity;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestEmbeddableEntityWithIDAnnotation extends SQLListenerTestCase{
+
+    public void setUp() {
+        setUp(EmbeddableEntityWithIDAnnotation.class, IDOwningClassTestEntity.class, CLEAR_TABLES);
       
+    }
+    
+    //make sure no exception is thrown here. 
+    public void testpcNewObjectIdInstanceMethod(){
+        EntityManager em = emf.createEntityManager();
+        try{
+            IDOwningClassTestEntity e = new IDOwningClassTestEntity();
+            em.getTransaction().begin();
+            em.persist(e);
+            em.getTransaction().commit();
+            assertTrue(em.createQuery("select count(c) from IDOwningClassTestEntity c", Long.class)
+                    .getSingleResult().longValue() > 0);                    
+        }finally{
+            em.close();
+        }
+    }
+
+}

Propchange: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestEmbeddableEntityWithIDAnnotation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/EmbeddableEntityWithIDAnnotation.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/EmbeddableEntityWithIDAnnotation.java?rev=1397306&view=auto
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/EmbeddableEntityWithIDAnnotation.java
(added)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/EmbeddableEntityWithIDAnnotation.java
Thu Oct 11 20:58:20 2012
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.openjpa.persistence.enhance.common.apps;
+
+// default package
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+
+/**
+ * BillingNoteId entity. @author MyEclipse Persistence Tools
+ */
+@Embeddable
+public class EmbeddableEntityWithIDAnnotation implements java.io.Serializable
+{
+
+	private static final long serialVersionUID = 558333273831654654L;
+
+	private Long id;
+
+    private Long seqNo = new Long(2012);
+
+    public EmbeddableEntityWithIDAnnotation( )
+    {
+    }
+
+    public EmbeddableEntityWithIDAnnotation( Long id, Long seqNo )
+    {
+        this.id = id;
+        this.seqNo = seqNo;
+    }
+
+    // Property accessors   
+    @Id
+    @Column(unique=true, nullable=false, precision=12, scale=0)  
+    public Long getId()
+    {
+        return this.id;
+    }
+
+    public void setId( Long id )
+    {
+        this.id = id;
+    }
+
+    @Column( name = "EmbeddableEntitySeqNo", nullable = false, precision = 12, scale = 0
)
+    public Long getSeqNo()
+    {
+        return this.seqNo;
+    }
+
+    public void setSeqNo( Long seqNo )
+    {
+        this.seqNo = seqNo;
+    }
+
+    public boolean equals( Object other )
+    {
+        if ( ( this == other ) )
+            return true;
+        if ( ( other == null ) )
+            return false;
+        if ( !( other instanceof EmbeddableEntityWithIDAnnotation ) )
+            return false;
+        EmbeddableEntityWithIDAnnotation castOther = ( EmbeddableEntityWithIDAnnotation )
other;
+
+        return ( ( this.getId( ) == castOther.getId( ) ) 
+        		|| ( this.getId( ) != null && castOther.getId( ) != null 
+        		&& this.getId( ).equals( castOther.getId( ) ) ) )
+                && ( ( this.getSeqNo( ) == castOther.getSeqNo( ) ) 
+                		|| ( this.getSeqNo( ) != null && castOther.getSeqNo( ) != null

+                		&& this.getSeqNo( ).equals( castOther.getSeqNo( ) ) ) );
+    }
+
+    public int hashCode()
+    {
+        int result = 17;
+
+        result = 37 * result + ( getId( ) == null ? 0 : this.getId( ).hashCode( ) );
+        result = 37 * result + ( getSeqNo( ) == null ? 0 : this.getSeqNo( ).hashCode( ) );
+        return result;
+    }
+
+}

Propchange: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/EmbeddableEntityWithIDAnnotation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/IDOwningClassTestEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/IDOwningClassTestEntity.java?rev=1397306&view=auto
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/IDOwningClassTestEntity.java
(added)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/IDOwningClassTestEntity.java
Thu Oct 11 20:58:20 2012
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.openjpa.persistence.enhance.common.apps;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+@Entity
+public class IDOwningClassTestEntity {
+    @EmbeddedId
+    EmbeddableEntityWithIDAnnotation pk = new EmbeddableEntityWithIDAnnotation(new Long(2012),
new Long(2000));
+    
+    String name;
+    
+}

Propchange: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/common/apps/IDOwningClassTestEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message