diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java index effd4c473..7cf3c535d 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java @@ -880,6 +880,11 @@ public class FieldMapping public Object loadProjection(JDBCStore store, JDBCFetchConfiguration fetch, Result res, Joins joins) throws SQLException { + // OPENJPA-662: Version fields have NoneFieldStrategy -- hence they + // need special treatment + if (isVersion()) { + return getDefiningMapping().getVersion().load(null, store, res); + } return assertStrategy().loadProjection(store, fetch, res, joins); } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Version.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Version.java index 3086daa5a..7a60a2d72 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Version.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Version.java @@ -338,9 +338,9 @@ public class Version return assertStrategy().select(sel, mapping); } - public void load(OpenJPAStateManager sm, JDBCStore store, Result res) + public Object load(OpenJPAStateManager sm, JDBCStore store, Result res) throws SQLException { - assertStrategy().load(sm, store, res); + return assertStrategy().load(sm, store, res); } public void afterLoad(OpenJPAStateManager sm, JDBCStore store) { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/VersionStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/VersionStrategy.java index 60c80c2f1..425e44c01 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/VersionStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/VersionStrategy.java @@ -53,7 +53,7 @@ public interface VersionStrategy /** * Load data. */ - public void load(OpenJPAStateManager sm, JDBCStore store, Result res) + public Object load(OpenJPAStateManager sm, JDBCStore store, Result res) throws SQLException; /** diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractVersionStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractVersionStrategy.java index b52cddc33..426e2231e 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractVersionStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractVersionStrategy.java @@ -53,8 +53,9 @@ public abstract class AbstractVersionStrategy return false; } - public void load(OpenJPAStateManager sm, JDBCStore store, Result res) + public Object load(OpenJPAStateManager sm, JDBCStore store, Result res) throws SQLException { + return null; } public void afterLoad(OpenJPAStateManager sm, JDBCStore store) { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java index 261e9c60b..b23c91649 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java @@ -178,13 +178,13 @@ public abstract class ColumnVersionStrategy return true; } - public void load(OpenJPAStateManager sm, JDBCStore store, Result res) + public Object load(OpenJPAStateManager sm, JDBCStore store, Result res) throws SQLException { // typically if one version column is in the result, they all are, so // optimize by checking for the first one before doing any real work Column[] cols = vers.getColumns(); if (!res.contains(cols[0])) - return; + return null; Object version = null; if (cols.length > 0) @@ -192,14 +192,18 @@ public abstract class ColumnVersionStrategy Object cur; for (int i = 0; i < cols.length; i++) { if (i > 0 && !res.contains(cols[i])) - return; + return null; cur = res.getObject(cols[i], -1, null); if (cols.length == 1) version = cur; else ((Object[]) version)[i] = cur; } - sm.setVersion(version); + // OPENJPA-662 Allow a null StateManager because this method may just be + // invoked to get the result of projection query + if (sm != null) + sm.setVersion(version); + return version; } public boolean checkVersion(OpenJPAStateManager sm, JDBCStore store,