mirror of https://github.com/apache/openjpa.git
OPENJPA-1954: ArrayIndexOutOfBoundsException when querying on a version field that is in a MappedSuperclass - back ported to 2.1.x Rick Curtis's commit to trunk.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1533233 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dd4daaebca
commit
50f9c75d14
|
@ -1075,9 +1075,14 @@ public class FieldMapping
|
|||
// version, it will have a NoneFieldMapping (since the version strategy
|
||||
// for the class takes care of it's mapping), and NoneFieldStrategies
|
||||
// do not have columns.
|
||||
if (isVersion())
|
||||
return getDeclaringMapping().getVersion().getColumns();
|
||||
else
|
||||
//
|
||||
// rgc : 2 March 2011 : Still hacky. If the version field is in a mapped super class we need to look
|
||||
// at the defining metadata to find the correct Version. Not sure why the version for the declaring metadata
|
||||
// is different than the defining metadata.
|
||||
if (isVersion()){
|
||||
ClassMapping cm = (ClassMapping)((FieldMetaData)this).getDefiningMetaData();
|
||||
return cm.getVersion().getColumns();
|
||||
}else
|
||||
return _val.getColumns();
|
||||
}
|
||||
|
||||
|
|
|
@ -2189,7 +2189,8 @@ public class DBDictionary
|
|||
if (augmentUpdates) {
|
||||
Path path = (Path) updateParams.keySet().iterator().next();
|
||||
FieldMapping fm = (FieldMapping) path.last();
|
||||
ClassMapping meta = fm.getDeclaringMapping();
|
||||
|
||||
ClassMapping meta = fm.getDefiningMapping();
|
||||
Map<Column,?> updates = meta.getVersion().getBulkUpdateValues();
|
||||
for (Map.Entry e : updates.entrySet()) {
|
||||
Column col = (Column) e.getKey();
|
||||
|
|
|
@ -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.persistence.jdbc.update;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class BaseTimestampedEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Version
|
||||
private Timestamp version;
|
||||
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Timestamp getVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
|
@ -19,9 +19,15 @@
|
|||
package org.apache.openjpa.persistence.jdbc.update;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
||||
import org.apache.openjpa.jdbc.meta.Version;
|
||||
import org.apache.openjpa.meta.MetaDataRepository;
|
||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
|
||||
/**
|
||||
|
@ -34,7 +40,15 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
|||
*/
|
||||
public class TestTimestampVersion extends SingleEMFTestCase {
|
||||
public void setUp() {
|
||||
super.setUp(CLEAR_TABLES, TimestampedEntity.class, NumericVersionedEntity.class);
|
||||
super.setUp(CLEAR_TABLES, TimestampedEntity.class, NumericVersionedEntity.class, BaseTimestampedEntity.class);
|
||||
}
|
||||
public void testQueryOnVersion() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
String pql = "SELECT s FROM TimestampedEntity s WHERE s.version < :endDate";
|
||||
Query queryObj = em.createQuery(pql);
|
||||
Timestamp t1 = new Timestamp((new Date()).getTime());
|
||||
queryObj.setParameter("endDate", t1);
|
||||
List<TimestampedEntity> scenarioList = queryObj.getResultList();
|
||||
}
|
||||
|
||||
public void testBulkUpdateOnTimestampedVersion() {
|
||||
|
@ -47,7 +61,7 @@ public class TestTimestampVersion extends SingleEMFTestCase {
|
|||
|
||||
try {
|
||||
// delay to ensure the new timestamp exceeds the timer's resolution.
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -18,13 +18,8 @@
|
|||
*/
|
||||
package org.apache.openjpa.persistence.jdbc.update;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
/**
|
||||
* An entity using a Timestamp as Version field.
|
||||
|
@ -35,31 +30,7 @@ import javax.persistence.Version;
|
|||
*/
|
||||
@Entity
|
||||
@Table(name="TSENTITY1")
|
||||
public class TimestampedEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Version
|
||||
private Timestamp version;
|
||||
|
||||
public class TimestampedEntity extends BaseTimestampedEntity{
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Timestamp getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue