mirror of https://github.com/apache/openjpa.git
OPENJPA-926 Do not validate access hierarchy when mapped superclass has no persistent attributes
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@783968 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
62be4544b3
commit
6ee7af451c
|
@ -2138,8 +2138,9 @@ public class ClassMetaData
|
|||
/**
|
||||
* Assert that this class' access type is allowed.
|
||||
* If no access style is set or an explicit style is set return.
|
||||
* Otherwise check that the superclass access style, if defaulted, is the
|
||||
* same as that of this receiver.
|
||||
* Otherwise, if the superclass has persistent attributes, check that
|
||||
* the superclass access style, if defaulted, is the same as that of this
|
||||
* receiver.
|
||||
*/
|
||||
private void validateAccessType() {
|
||||
if (AccessCode.isEmpty(_accessType)
|
||||
|
@ -2148,7 +2149,7 @@ public class ClassMetaData
|
|||
ClassMetaData sup = getPCSuperclassMetaData();
|
||||
while (sup != null && sup.isExplicitAccess())
|
||||
sup = sup.getPCSuperclassMetaData();
|
||||
if (sup != null) {
|
||||
if (sup != null && sup.getDeclaredFields().length > 0) {
|
||||
int supCode = sup.getAccessType();
|
||||
if (!AccessCode.isCompatibleSuper(_accessType, supCode))
|
||||
throw new MetaDataException(_loc.get("access-inconsistent-inherit",
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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.access;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.PrePersist;
|
||||
|
||||
/*
|
||||
* Mapped superclass which contains no persistent attributes, but contains
|
||||
* a callback.
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class MappedCallbackSup {
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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.access;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class PropEntity extends MappedCallbackSup {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Id
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Basic
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
package org.apache.openjpa.persistence.access;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
||||
|
@ -31,55 +34,81 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
|||
|
||||
public class TestDefaultAccess extends SingleEMFTestCase {
|
||||
|
||||
public void setUp() {
|
||||
setUp(CLEAR_TABLES,
|
||||
PropEntity.class, MappedCallbackSup.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates that an property access entity extending a mapped superclass
|
||||
* containing no persistent fields (only a callback) does not cause access
|
||||
* validation failures.
|
||||
*/
|
||||
public void testDefaultMappedSuperclassAccess() {
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
PropEntity pe = new PropEntity();
|
||||
|
||||
pe.setId(new Random().nextInt());
|
||||
pe.setName("Name");
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(pe);
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates use of access specifier of FIELD in entity-mappings.
|
||||
*/
|
||||
public void testEMDefaultFieldAccess() {
|
||||
OpenJPAEntityManagerFactorySPI emf =
|
||||
OpenJPAEntityManagerFactorySPI emf1 =
|
||||
(OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
|
||||
createEntityManagerFactory("Access-EMFldDef",
|
||||
"org/apache/openjpa/persistence/access/" +
|
||||
"access-def-persistence.xml");
|
||||
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
OpenJPAEntityManagerSPI em = emf1.createEntityManager();
|
||||
verifyDefaultFieldAccess(em);
|
||||
|
||||
em.close();
|
||||
emf.close();
|
||||
emf1.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates use of access specifier of PROPERTY in entity-mappings.
|
||||
*/
|
||||
public void testEMDefaultPropertyAccess() {
|
||||
OpenJPAEntityManagerFactorySPI emf =
|
||||
OpenJPAEntityManagerFactorySPI emf1 =
|
||||
(OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
|
||||
createEntityManagerFactory("Access-EMPropDef",
|
||||
"org/apache/openjpa/persistence/access/" +
|
||||
"access-def-persistence.xml");
|
||||
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
OpenJPAEntityManagerSPI em = emf1.createEntityManager();
|
||||
verifyDefaultPropertyAccess(em);
|
||||
|
||||
em.close();
|
||||
emf.close();
|
||||
emf1.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates use of access specifier of FIELD in persistence unit defaults.
|
||||
*/
|
||||
public void testPUDefaultFieldAccess() {
|
||||
OpenJPAEntityManagerFactorySPI emf =
|
||||
OpenJPAEntityManagerFactorySPI emf1 =
|
||||
(OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
|
||||
createEntityManagerFactory("Access-PUFldDef",
|
||||
"org/apache/openjpa/persistence/access/" +
|
||||
"access-pudef-persistence.xml");
|
||||
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
OpenJPAEntityManagerSPI em = emf1.createEntityManager();
|
||||
verifyDefaultFieldAccess(em);
|
||||
|
||||
em.close();
|
||||
emf.close();
|
||||
emf1.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,17 +116,17 @@ public class TestDefaultAccess extends SingleEMFTestCase {
|
|||
* defaults.
|
||||
*/
|
||||
public void testPUDefaultPropertyAccess() {
|
||||
OpenJPAEntityManagerFactorySPI emf =
|
||||
OpenJPAEntityManagerFactorySPI emf1 =
|
||||
(OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
|
||||
createEntityManagerFactory("Access-PUPropDef",
|
||||
"org/apache/openjpa/persistence/access/" +
|
||||
"access-pudef-persistence.xml");
|
||||
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
OpenJPAEntityManagerSPI em = emf1.createEntityManager();
|
||||
verifyDefaultPropertyAccess(em);
|
||||
|
||||
em.close();
|
||||
emf.close();
|
||||
emf1.close();
|
||||
}
|
||||
|
||||
private void verifyDefaultFieldAccess(OpenJPAEntityManagerSPI em) {
|
||||
|
|
Loading…
Reference in New Issue