OPENJPA-1100: Raise exception for unsupported version field type rather than silently ignoring

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@808725 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-08-28 01:39:15 +00:00
parent 149dbef93b
commit 250186fbcb
3 changed files with 85 additions and 2 deletions

View File

@ -96,6 +96,7 @@ import org.apache.openjpa.meta.Order;
import org.apache.openjpa.meta.SequenceMetaData; import org.apache.openjpa.meta.SequenceMetaData;
import org.apache.openjpa.meta.ValueMetaData; import org.apache.openjpa.meta.ValueMetaData;
import org.apache.openjpa.util.MetaDataException; import org.apache.openjpa.util.MetaDataException;
import org.apache.openjpa.util.UserException;
/** /**
* Repository of object/relational mapping information. * Repository of object/relational mapping information.
@ -1266,7 +1267,8 @@ public class MappingRepository
case JavaTypes.NUMBER: case JavaTypes.NUMBER:
return new NumberVersionStrategy(); return new NumberVersionStrategy();
default: default:
return NoneVersionStrategy.getInstance(); throw new UserException(_loc.get("version-type-unsupported", vfield, vfield.getDeclaredType()));
// return NoneVersionStrategy.getInstance();
} }
} }

View File

@ -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 \ mapping of class "{1}" because the table does neither match its primary \
table "{2}" nor any of its secondary table(s) "{3}". table "{2}" nor any of its secondary table(s) "{3}".
bad-version-column-table: One of the version column "{0}" has been associated \ 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. with table "{1}", but no primary or secondary table of such name exists.
version-type-unsupported: Version field "{0}" of {1} is not supported.

View File

@ -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.
* <BR>
* For more details refer
*
* <A HREF="https://issues.apache.org/jira/browse/OPENJPA-1100">OPENJPA-1100</A>
*
* @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;
}
}
}