mirror of https://github.com/apache/openjpa.git
OPENJPA-859: Recommitting 818928. Added new test scenario for partial xml defined embeddable that implements Serializable.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@828072 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c753ce2278
commit
f7568decb9
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* 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/LICENSE2.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;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
import org.apache.openjpa.persistence.entity.MixedMappingLocation;
|
||||||
|
import org.apache.openjpa.persistence.entity.MixedMappingLocationEmbeddedId;
|
||||||
|
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||||
|
|
||||||
|
// org.apache.openjpa.persistence.TestMixedMappingLocation
|
||||||
|
@Entity
|
||||||
|
public class TestMixedMappingLocation extends SingleEMFTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getPersistenceUnitName() {
|
||||||
|
return "test_parsing";
|
||||||
|
}
|
||||||
|
public void setUp() {
|
||||||
|
setUp(DROP_TABLES,MixedMappingLocationEmbeddedId.class, MixedMappingLocation.class);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Testcase for added OPENJPA859.
|
||||||
|
*
|
||||||
|
* This scenario is testing whether the default annotations are being generated for a class that
|
||||||
|
* isn't annotated with a persistence class type (ie: @Entity, @MappedSuperclass, @Embeddable),
|
||||||
|
* but it is in a mapping file.
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void testMixedOrmAnno() throws Exception {
|
||||||
|
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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/LICENSE2.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.entity;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class doesn't have an @Entity and @Basic on purpose.
|
||||||
|
*/
|
||||||
|
public class MixedMappingLocation {
|
||||||
|
MixedMappingLocationEmbeddedId id;
|
||||||
|
|
||||||
|
String basic1;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
String basic2;
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* 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/LICENSE2.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.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
public class MixedMappingLocationEmbeddedId implements Serializable {
|
||||||
|
@Transient
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Basic
|
||||||
|
private int id;
|
||||||
|
@Basic
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
public MixedMappingLocationEmbeddedId() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return super.equals(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return super.hashCode();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
|
||||||
|
<entity class="org.apache.openjpa.persistence.entity.MixedMappingLocation">
|
||||||
|
<attributes>
|
||||||
|
<embedded-id name="id"></embedded-id>
|
||||||
|
<basic name="basic1">
|
||||||
|
<column name="basic1_override" length="100"/>
|
||||||
|
</basic>
|
||||||
|
</attributes>
|
||||||
|
</entity>
|
||||||
|
<embeddable class="org.apache.openjpa.persistence.entity.MixedMappingLocationEmbeddedId"></embeddable>
|
||||||
|
</entity-mappings>
|
|
@ -256,6 +256,12 @@
|
||||||
<class>org.apache.openjpa.persistence.meta.MdrTestEntity</class>
|
<class>org.apache.openjpa.persistence.meta.MdrTestEntity</class>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
<persistence-unit name="test_parsing">
|
||||||
|
<mapping-file>org/apache/openjpa/persistence/entity/orm.xml</mapping-file>
|
||||||
|
<class>org.apache.openjpa.persistence.entity.MixedMappingLocation</class>
|
||||||
|
<class>org.apache.openjpa.persistence.entity.MixedMappingLocationEmbeddedId</class>
|
||||||
|
</persistence-unit>
|
||||||
|
|
||||||
<persistence-unit name="mapsId-pu">
|
<persistence-unit name="mapsId-pu">
|
||||||
<mapping-file>org/apache/openjpa/persistence/enhance/identity/mapsId-orm.xml</mapping-file>
|
<mapping-file>org/apache/openjpa/persistence/enhance/identity/mapsId-orm.xml</mapping-file>
|
||||||
<class>org.apache.openjpa.persistence.enhance.identity.Employee1Xml</class>
|
<class>org.apache.openjpa.persistence.enhance.identity.Employee1Xml</class>
|
||||||
|
|
|
@ -491,21 +491,22 @@ public class AnnotationPersistenceMetaDataParser
|
||||||
* Read annotations for the current type.
|
* Read annotations for the current type.
|
||||||
*/
|
*/
|
||||||
private ClassMetaData parseClassAnnotations() {
|
private ClassMetaData parseClassAnnotations() {
|
||||||
// check immediately whether the user is using any annotations,
|
// Check to see if there is cached metadata for the class that we are currently parsing. It
|
||||||
// regardless of mode. this prevents adding non-entity classes to
|
// is possible that one of the annotations (Entity, Embeddable, MappedSuperclass) is in the
|
||||||
// repository if we're ignoring these annotations in mapping mode
|
// orm.xml. We still need to look at these files for other annotations and more importantly
|
||||||
if (!(AccessController.doPrivileged(J2DoPrivHelper
|
// setup defaults (ie: Basic fields).
|
||||||
.isAnnotationPresentAction(_cls, Entity.class))).booleanValue()
|
ClassMetaData m = getRepository().getCachedMetaData(_cls);
|
||||||
&& !(AccessController.doPrivileged(J2DoPrivHelper
|
if (m == null) {
|
||||||
.isAnnotationPresentAction(_cls, Embeddable.class)))
|
if (!(AccessController.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls, Entity.class)))
|
||||||
.booleanValue()
|
.booleanValue()
|
||||||
&& !(AccessController.doPrivileged(J2DoPrivHelper
|
&& !(AccessController.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls, Embeddable.class)))
|
||||||
.isAnnotationPresentAction(_cls, MappedSuperclass.class)))
|
.booleanValue()
|
||||||
.booleanValue())
|
&& !(AccessController.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls,
|
||||||
|
MappedSuperclass.class))).booleanValue())
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
// find / create metadata
|
// find / create metadata
|
||||||
ClassMetaData meta = getMetaData();
|
ClassMetaData meta = (m == null) ? getMetaData() : m;
|
||||||
if (meta == null)
|
if (meta == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
|
@ -1063,6 +1063,7 @@ public class XMLPersistenceMetaDataParser
|
||||||
fmd.setExplicit(true);
|
fmd.setExplicit(true);
|
||||||
fmd.setPrimaryKey(true);
|
fmd.setPrimaryKey(true);
|
||||||
fmd.setEmbedded(true);
|
fmd.setEmbedded(true);
|
||||||
|
fmd.setSerialized(false);
|
||||||
if (fmd.getEmbeddedMetaData() == null)
|
if (fmd.getEmbeddedMetaData() == null)
|
||||||
// fmd.addEmbeddedMetaData();
|
// fmd.addEmbeddedMetaData();
|
||||||
deferEmbeddable(fmd.getDeclaredType(), fmd);
|
deferEmbeddable(fmd.getDeclaredType(), fmd);
|
||||||
|
|
Loading…
Reference in New Issue