diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
index 62b317fe3..6af248705 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
@@ -117,7 +117,7 @@ public class PCEnhancer {
// public int getEnhancementContractVersion()
public static final int ENHANCER_VERSION = 2;
- boolean _addVersionInitFlag = true;
+ boolean _addVersionInitFlag = true;
public static final int ENHANCE_NONE = 0;
public static final int ENHANCE_AWARE = 2 << 0;
@@ -2772,7 +2772,7 @@ public class PCEnhancer {
_pc.declareField(PRE + "FieldTypes", Class[].class).setStatic(true);
_pc.declareField(PRE + "FieldFlags", byte[].class).setStatic(true);
_pc.declareField(SUPER, Class.class).setStatic(true);
- if(_addVersionInitFlag && _meta.getVersionField()!=null){
+ if (_addVersionInitFlag && _meta.getVersionField() != null) {
// protected transient boolean pcVersionInit;
BCField field = _pc.declareField(VERSION_INIT_STR, boolean.class);
field.makeProtected();
@@ -3229,17 +3229,15 @@ public class PCEnhancer {
if (!_addVersionInitFlag){
// else return false;
ifins.setTarget(code.getstatic().setField(Boolean.class, "FALSE", Boolean.class));
- }else{
- FieldMetaData versionInit = _meta.getDeclaredField(VERSION_INIT_STR);
-
+ }else{
// noop
ifins.setTarget(code.nop());
// if (pcVersionInit != false)
// return true
// else return false;
loadManagedInstance(code, false);
- getfield(code, null, versionInit.getName());
- ifins = ifDefaultValue(code, versionInit);
+ getfield(code, null, VERSION_INIT_STR);
+ ifins = code.ifeq();
code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
code.areturn();
ifins.setTarget(code.nop());
@@ -3709,12 +3707,10 @@ public class PCEnhancer {
addSetManagedValueCode(code, fmd);
if(fmd.isVersion()==true && _addVersionInitFlag){
// if we are setting the version, flip the versionInit flag to true
- FieldMetaData v = _meta.addDeclaredField(VERSION_INIT_STR, boolean.class);
- v.setTransient(true);
loadManagedInstance(code, true);
code.constant().setValue(1);
// pcVersionInit = true;
- putfield(code, null, v.getName(), v.getDeclaredType());
+ putfield(code, null, VERSION_INIT_STR, boolean.class);
}
code.vreturn();
diff --git a/openjpa-persistence-jdbc/src/main/ant/enhancer.xml b/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
index badba7efd..3359bfd9a 100644
--- a/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
+++ b/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
@@ -75,6 +75,7 @@
dir="${project.build.testOutputDirectory}">
+
@@ -92,6 +93,7 @@
+
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java
new file mode 100644
index 000000000..c1d57752c
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java
@@ -0,0 +1,48 @@
+/*
+ * 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.detach.serializable;
+
+import java.io.Serializable;
+import java.sql.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Version;
+
+@Entity
+public class SerializableDetachedStateManager implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 80701492251635740L;
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.AUTO)
+ int id;
+
+ @Version
+ int version;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ Date zDate;
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java
new file mode 100644
index 000000000..eff31de11
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java
@@ -0,0 +1,44 @@
+/*
+ * 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.detach.serializable;
+
+import java.sql.Date;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSerializableDetachedStateManager extends SingleEMFTestCase {
+ public void setUp() {
+ setUp(CLEAR_TABLES, SerializableDetachedStateManager.class, DROP_TABLES, "openjpa.DetachState",
+ "fgs(DetachedStateField=true)");
+ }
+
+ public void testRoundTrip() throws Exception {
+ SerializableDetachedStateManager c = new SerializableDetachedStateManager();
+ c.zDate = new Date(System.currentTimeMillis());
+ OpenJPAEntityManagerSPI em = emf.createEntityManager();
+
+ em.getTransaction().begin();
+ em.persist(c);
+ em.getTransaction().commit();
+ em.close();
+ AbstractPersistenceTestCase.roundtrip(c);
+ }
+}