diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java index ecc5e47cd..bdc8f520b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java @@ -96,6 +96,7 @@ import org.apache.openjpa.meta.Order; import org.apache.openjpa.meta.SequenceMetaData; import org.apache.openjpa.meta.ValueMetaData; import org.apache.openjpa.util.MetaDataException; +import org.apache.openjpa.util.UserException; /** * Repository of object/relational mapping information. @@ -1266,7 +1267,8 @@ public class MappingRepository case JavaTypes.NUMBER: return new NumberVersionStrategy(); default: - return NoneVersionStrategy.getInstance(); + throw new UserException(_loc.get("version-type-unsupported", vfield, vfield.getDeclaredType())); +// return NoneVersionStrategy.getInstance(); } } diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties index 94f8be278..841df94af 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties @@ -416,4 +416,5 @@ unique-no-table: A unique constraint on table "{0}" can not be added to \ mapping of class "{1}" because the table does neither match its primary \ table "{2}" nor any of its secondary table(s) "{3}". bad-version-column-table: One of the version column "{0}" has been associated \ - with table "{1}", but no primary or secondary table of such name exists. \ No newline at end of file + with table "{1}", but no primary or secondary table of such name exists. +version-type-unsupported: Version field "{0}" of {1} is not supported. \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jira1100/TestBadVersionField.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jira1100/TestBadVersionField.java new file mode 100644 index 000000000..12817beb2 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jira1100/TestBadVersionField.java @@ -0,0 +1,80 @@ +/* + * 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.jira1100; + +import java.math.BigDecimal; + +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Version; + +import org.apache.openjpa.persistence.test.SingleEMFTestCase; + +/** + * Tests that entity with unsupported version type can not be used. + * Used to ignore such field silently before. + *
+ * For more details refer + * + * OPENJPA-1100 + * + * @author Pinaki Poddar + * + */ +public class TestBadVersionField extends SingleEMFTestCase { + public void setUp() { + super.setUp(CLEAR_TABLES, Data.class); + } + + public void testWrongVersionFieldNotSupported() { + try { + EntityManager em = emf.createEntityManager(); + fail("Expected to fail with unsupported Version field type"); + } catch (Exception ex) { + + } + } + + /** + * Declares a Version field of unsupported type. + * + */ + @Entity + @Table(name="BadVersionField") + public class Data { + @Id + @GeneratedValue + private long id; + + @Version + private BigDecimal version; + + public long getId() { + return id; + } + + public BigDecimal getVersion() { + return version; + } + } + +}