mirror of https://github.com/apache/openjpa.git
OPENJPA-1270: check in test case for this JIRA
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@813125 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ed40459a2a
commit
94a0bc3781
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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.compat;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="MPSP_A")
|
||||||
|
public class EntityA extends MappedSuper {
|
||||||
|
|
||||||
|
@Column(length=30)
|
||||||
|
@Basic(fetch=FetchType.LAZY)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* 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.compat;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="MPSP_B")
|
||||||
|
public class EntityB {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
int id;
|
||||||
|
|
||||||
|
@Column(length=30)
|
||||||
|
@Basic(fetch=FetchType.LAZY)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
EntityA entityA;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityA getEntityA() {
|
||||||
|
return entityA;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntityA(EntityA entityA) {
|
||||||
|
this.entityA = entityA;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* 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.compat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.MappedSuperclass;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.Version;
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
public abstract class MappedSuper {
|
||||||
|
private static final long serialVersionUID = -3613354849799979342L;
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date lastUpdateDate;
|
||||||
|
|
||||||
|
@Version
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@OneToOne(mappedBy="entityA")
|
||||||
|
EntityB entityB;
|
||||||
|
|
||||||
|
public int getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(int version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdateDate() {
|
||||||
|
return lastUpdateDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdateDate(Date lastUpdateDate) {
|
||||||
|
this.lastUpdateDate = lastUpdateDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityB getEntityB() {
|
||||||
|
return entityB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntityB(EntityB entityB) {
|
||||||
|
this.entityB = entityB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,12 +18,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.compat;
|
package org.apache.openjpa.persistence.compat;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.apache.openjpa.conf.Compatibility;
|
import org.apache.openjpa.conf.Compatibility;
|
||||||
import org.apache.openjpa.conf.Specification;
|
import org.apache.openjpa.conf.Specification;
|
||||||
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
||||||
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
||||||
import org.apache.openjpa.persistence.test.AbstractCachedEMFTestCase;
|
import org.apache.openjpa.persistence.test.AbstractCachedEMFTestCase;
|
||||||
import org.apache.openjpa.persistence.test.PersistenceTestCase;
|
|
||||||
|
|
||||||
public class TestSpecCompatibilityOptions
|
public class TestSpecCompatibilityOptions
|
||||||
extends AbstractCachedEMFTestCase {
|
extends AbstractCachedEMFTestCase {
|
||||||
|
@ -76,4 +77,40 @@ extends AbstractCachedEMFTestCase {
|
||||||
|
|
||||||
emf.close();
|
emf.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Per JPA 2.0, Relationships in mapped superclass must be unidirectional.
|
||||||
|
* An exceptioin will be thrown when a bi-directional relation is detected in
|
||||||
|
* a mapped superclass.
|
||||||
|
*/
|
||||||
|
public void testMappedSuperClass() {
|
||||||
|
OpenJPAEntityManagerFactorySPI emf =
|
||||||
|
(OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
|
||||||
|
createEntityManagerFactory("persistence_2_0",
|
||||||
|
"org/apache/openjpa/persistence/compat/" +
|
||||||
|
"persistence_2_0.xml");
|
||||||
|
EntityManager em = null;
|
||||||
|
try {
|
||||||
|
em = emf.createEntityManager();
|
||||||
|
EntityA a = new EntityA();
|
||||||
|
a.setId(1);
|
||||||
|
EntityB b = new EntityB();
|
||||||
|
b.setId(1);
|
||||||
|
a.setEntityB(b);
|
||||||
|
b.setEntityA(a);
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.persist(a);
|
||||||
|
em.persist(b);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
fail("An exceptioin will be thrown for a bi-directional relation declared in mapped superclass");
|
||||||
|
} catch (org.apache.openjpa.persistence.ArgumentException e) {
|
||||||
|
if (em != null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
emf.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,9 @@
|
||||||
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
|
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
|
||||||
version="2.0" >
|
version="2.0" >
|
||||||
<persistence-unit name="persistence_2_0" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="persistence_2_0" transaction-type="RESOURCE_LOCAL">
|
||||||
|
<class>org.apache.openjpa.persistence.compat.EntityA</class>
|
||||||
|
<class>org.apache.openjpa.persistence.compat.EntityB</class>
|
||||||
|
<class>org.apache.openjpa.persistence.compat.MappedSuper</class>
|
||||||
|
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
Loading…
Reference in New Issue