Author: pcl
Date: Tue Aug 21 18:33:40 2007
New Revision: 568363
URL: http://svn.apache.org/viewvc?rev=568363&view=rev
Log:
OpenJPA used to rely on being able to implicitly specify a value for a
@GeneratedValue field when using an IDENTITY generation strategy. Now that we
do not allow that behavior, OpenJPA was failing to generate IDs properly in
some cases. Fixed.
Added:
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestDataCachingAndUnenhancedPropertyAccess.java
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedIdentityIdPropertyAccess.java
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/IdentityIdClass.java
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestAutoIncrementAndDataCaching.java
Modified:
openjpa/branches/1.0.0/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
Modified:
openjpa/branches/1.0.0/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.0/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java?rev=568363&r1=568362&r2=568363&view=diff
==============================================================================
---
openjpa/branches/1.0.0/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
(original)
+++
openjpa/branches/1.0.0/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
Tue Aug 21 18:33:40 2007
@@ -32,8 +32,10 @@
import org.apache.openjpa.jdbc.sql.SQLExceptions;
import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.util.ApplicationIds;
import org.apache.openjpa.util.OpenJPAException;
import org.apache.openjpa.util.OptimisticException;
+import org.apache.openjpa.meta.ClassMetaData;
/**
* Basic prepared statement manager implementation.
@@ -119,6 +121,8 @@
mapping.assertJoinable(autoAssign[i]).setAutoAssignedValue(sm,
_store, autoAssign[i], val);
}
+ sm.setObjectId(
+ ApplicationIds.create(sm.getPersistenceCapable(), mapping));
}
}
Added:
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestDataCachingAndUnenhancedPropertyAccess.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestDataCachingAndUnenhancedPropertyAccess.java?rev=568363&view=auto
==============================================================================
---
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestDataCachingAndUnenhancedPropertyAccess.java
(added)
+++
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestDataCachingAndUnenhancedPropertyAccess.java
Tue Aug 21 18:33:40 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.enhance;
+
+import java.util.List;
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestDataCachingAndUnenhancedPropertyAccess
+ extends SingleEMFTestCase {
+
+ @Override
+ public void setUp() {
+ setUp(UnenhancedIdentityIdPropertyAccess.class, CLEAR_TABLES,
+ "openjpa.DataCache", "true",
+ "openjpa.RemoteCommitProvider", "sjvm");
+ }
+
+ public void testSimpleDataCacheOperation() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ em.persist(new UnenhancedIdentityIdPropertyAccess());
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testAccessIdBeforeCommit() {
+ OpenJPAEntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ UnenhancedIdentityIdPropertyAccess o =
+ new UnenhancedIdentityIdPropertyAccess();
+ em.persist(o);
+ em.getObjectId(o);
+ em.getTransaction().commit();
+ em.close();
+ }
+}
\ No newline at end of file
Added:
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedIdentityIdPropertyAccess.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedIdentityIdPropertyAccess.java?rev=568363&view=auto
==============================================================================
---
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedIdentityIdPropertyAccess.java
(added)
+++
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedIdentityIdPropertyAccess.java
Tue Aug 21 18:33:40 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.enhance;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.PrePersist;
+
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
[EMAIL PROTECTED]
+public class UnenhancedIdentityIdPropertyAccess {
+
+ private int id;
+ private String stringField;
+
+ public UnenhancedIdentityIdPropertyAccess() {
+ }
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStringField() {
+ return stringField;
+ }
+
+ public void setStringField(String stringField) {
+ this.stringField = stringField;
+ }
+}
Added:
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/IdentityIdClass.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/IdentityIdClass.java?rev=568363&view=auto
==============================================================================
---
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/IdentityIdClass.java
(added)
+++
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/IdentityIdClass.java
Tue Aug 21 18:33:40 2007
@@ -0,0 +1,33 @@
+/*
+ * 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.datacache;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
[EMAIL PROTECTED]
+public class IdentityIdClass {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private int id;
+
+ private String stringField;
+}
Added:
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestAutoIncrementAndDataCaching.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestAutoIncrementAndDataCaching.java?rev=568363&view=auto
==============================================================================
---
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestAutoIncrementAndDataCaching.java
(added)
+++
openjpa/branches/1.0.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestAutoIncrementAndDataCaching.java
Tue Aug 21 18:33:40 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.datacache;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestAutoIncrementAndDataCaching
+ extends SingleEMFTestCase {
+
+ @Override
+ public void setUp() {
+ setUp(IdentityIdClass.class, CLEAR_TABLES,
+ "openjpa.DataCache", "true",
+ "openjpa.RemoteCommitProvider", "sjvm");
+ }
+
+ public void testSimpleDataCacheOperation() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ em.persist(new IdentityIdClass());
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testAccessIdBeforeCommit() {
+ OpenJPAEntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ IdentityIdClass o = new IdentityIdClass();
+ em.persist(o);
+ em.getObjectId(o);
+ em.getTransaction().commit();
+ em.close();
+ }
+}
\ No newline at end of file