mirror of https://github.com/apache/openjpa.git
OPENJPA-2325: Test cases for Mapped Super Class without identity field
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1436960 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
01cae73832
commit
e63abd92a7
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* 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.inheritance.mappedsuperclass;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.MappedSuperclass;
|
||||||
|
import javax.persistence.Version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Mapped Super Class without a declared identity field. The derived classes
|
||||||
|
* declare identity.
|
||||||
|
*
|
||||||
|
* @author Pinaki Poddar
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class DerivedEntityFromMappedSuperWithoutId extends MappedSuperWithoutId {
|
||||||
|
@Id
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Version
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(int version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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.inheritance.mappedsuperclass;
|
||||||
|
|
||||||
|
import javax.persistence.MappedSuperclass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Mapped Super Class without a declared identity field. The derived classes
|
||||||
|
* declare identity.
|
||||||
|
*
|
||||||
|
* @author Pinaki Poddar
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
public class MappedSuperWithoutId {
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.description = desc;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,16 +28,22 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||||
/**
|
/**
|
||||||
* Test case and domain classes were originally part of the reported issue
|
* Test case and domain classes were originally part of the reported issue
|
||||||
* <A href="https://issues.apache.org/jira/browse/OPENJPA-873">OPENJPA-873</A>
|
* <A href="https://issues.apache.org/jira/browse/OPENJPA-873">OPENJPA-873</A>
|
||||||
*
|
* <p>
|
||||||
|
* Added a new test where mapped super class does not decalre an identity.
|
||||||
|
* Originally reported
|
||||||
|
* <A href="https://issues.apache.org/jira/browse/OPENJPA-2325">OPENJPA-2325</A>
|
||||||
|
*
|
||||||
* @author pioneer_ip@yahoo.com
|
* @author pioneer_ip@yahoo.com
|
||||||
* @author Fay Wang
|
* @author Fay Wang
|
||||||
*
|
* @author Pinaki Poddar
|
||||||
*/
|
*/
|
||||||
public class TestMappedSuperClass extends SingleEMFTestCase {
|
public class TestMappedSuperClass extends SingleEMFTestCase {
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
setUp(CashBaseEntity.class,
|
setUp(CashBaseEntity.class,
|
||||||
SituationDA.class, ValuableItemDA.class, CLEAR_TABLES);
|
SituationDA.class, ValuableItemDA.class,
|
||||||
|
MappedSuperWithoutId.class, DerivedEntityFromMappedSuperWithoutId.class,
|
||||||
|
CLEAR_TABLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMappedSuperClass() {
|
public void testMappedSuperClass() {
|
||||||
|
@ -73,4 +79,35 @@ public class TestMappedSuperClass extends SingleEMFTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that new entity can be merged when the entity is derived from a mapped
|
||||||
|
* super class that does not declare an identity field.
|
||||||
|
*/
|
||||||
|
public void testMergeNewInstanceDerivedFromMappedSuperClassWithoutIdentityField() {
|
||||||
|
EntityManager em = emf.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
final long id = System.currentTimeMillis();
|
||||||
|
DerivedEntityFromMappedSuperWithoutId pc = new DerivedEntityFromMappedSuperWithoutId();
|
||||||
|
pc.setId(id);
|
||||||
|
pc.setName("abc");
|
||||||
|
em.persist(pc);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
|
||||||
|
DerivedEntityFromMappedSuperWithoutId newpc = new DerivedEntityFromMappedSuperWithoutId();
|
||||||
|
em = emf.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
newpc.setId(id);
|
||||||
|
newpc.setName("xyz");
|
||||||
|
em.merge(newpc);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
|
||||||
|
em = emf.createEntityManager();
|
||||||
|
DerivedEntityFromMappedSuperWithoutId found = em.find(DerivedEntityFromMappedSuperWithoutId.class, id);
|
||||||
|
assertNotNull(found);
|
||||||
|
assertEquals("xyz", found.getName());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue