HHH-4691 - xml access type support for embedded-id and embedded
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18519 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
b1f925458e
commit
4224e74d1a
|
@ -1,4 +1,4 @@
|
|||
// $Id:$
|
||||
// $Id$
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
|
@ -839,6 +839,7 @@ public class JPAOverridenAnnotationReader implements AnnotationReader {
|
|||
if ( "embedded".equals( element.getName() ) ) {
|
||||
AnnotationDescriptor ad = new AnnotationDescriptor( Embedded.class );
|
||||
annotationList.add( AnnotationFactory.create( ad ) );
|
||||
getAccessType( annotationList, element );
|
||||
}
|
||||
}
|
||||
if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) {
|
||||
|
@ -985,6 +986,7 @@ public class JPAOverridenAnnotationReader implements AnnotationReader {
|
|||
addIfNotNull( annotationList, annotation );
|
||||
AnnotationDescriptor ad = new AnnotationDescriptor( EmbeddedId.class );
|
||||
annotationList.add( AnnotationFactory.create( ad ) );
|
||||
getAccessType( annotationList, element );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
// $Id$
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* Licensed 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.hibernate.test.annotations.access.xml;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@Entity
|
||||
public class Cook {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
private Knive favouriteKnife;
|
||||
|
||||
public Knive getFavouriteKnife() {
|
||||
return favouriteKnife;
|
||||
}
|
||||
|
||||
public void setFavouriteKnife(Knive favouriteKnife) {
|
||||
this.favouriteKnife = favouriteKnife;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// $Id: Waiter.java 18506 2010-01-11 20:23:08Z hardy.ferentschik $
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* Licensed 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.hibernate.test.annotations.access.xml;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@Embeddable
|
||||
public class Knive {
|
||||
private String brand;
|
||||
|
||||
private int bladeLength;
|
||||
|
||||
public int getBladeLength() {
|
||||
return bladeLength;
|
||||
}
|
||||
|
||||
public void setBladeLength(int bladeLength) {
|
||||
this.bladeLength = bladeLength;
|
||||
}
|
||||
|
||||
public String getBrand() {
|
||||
return brand;
|
||||
}
|
||||
|
||||
public void setBrand(String brand) {
|
||||
this.brand = brand;
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ public class XmlAccessTest extends TestCase {
|
|||
|
||||
// now with an additional xml configuration file changing the default access type for Tourist using basic
|
||||
configFiles = new ArrayList<String>();
|
||||
configFiles.add("org/hibernate/test/annotations/access/xml/Tourist.xml");
|
||||
configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist.xml" );
|
||||
factory = buildSessionFactory( classes, configFiles );
|
||||
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class XmlAccessTest extends TestCase {
|
|||
Class<?> classUnderTest = Waiter.class;
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
classes.add( classUnderTest );
|
||||
classes.add(Crew.class);
|
||||
classes.add( Crew.class );
|
||||
List<String> configFiles = new ArrayList<String>();
|
||||
configFiles.add( "org/hibernate/test/annotations/access/xml/Crew.xml" );
|
||||
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
|
||||
|
@ -131,13 +131,24 @@ public class XmlAccessTest extends TestCase {
|
|||
Class<?> classUnderTest = RentalCar.class;
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
classes.add( classUnderTest );
|
||||
classes.add(Driver.class);
|
||||
classes.add( Driver.class );
|
||||
List<String> configFiles = new ArrayList<String>();
|
||||
configFiles.add( "org/hibernate/test/annotations/access/xml/RentalCar.xml" );
|
||||
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
|
||||
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
|
||||
}
|
||||
|
||||
public void testAccessOnEmbeddedXmlElement() throws Exception {
|
||||
Class<?> classUnderTest = Cook.class;
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
classes.add( classUnderTest );
|
||||
classes.add( Knive.class );
|
||||
List<String> configFiles = new ArrayList<String>();
|
||||
configFiles.add( "org/hibernate/test/annotations/access/xml/Cook.xml" );
|
||||
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
|
||||
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
|
||||
}
|
||||
|
||||
private SessionFactoryImplementor buildSessionFactory(List<Class<?>> classesUnderTest, List<String> configFiles) {
|
||||
assert classesUnderTest != null;
|
||||
assert configFiles != null;
|
||||
|
@ -153,6 +164,7 @@ public class XmlAccessTest extends TestCase {
|
|||
}
|
||||
|
||||
// uses the first getter of the tupelizer for the assertions
|
||||
|
||||
private void assertAccessType(SessionFactoryImplementor factory, Class<?> classUnderTest, AccessType accessType) {
|
||||
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
|
||||
.getEntityMetamodel();
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm file:/Users/hardy/work/hibernate/core/trunk/annotations/src/main/resources/org/hibernate/ejb/orm_2_0.xsd"
|
||||
version="2.0">
|
||||
<package>org.hibernate.test.annotations.access.xml</package>
|
||||
<entity class="Cook" metadata-complete="false">
|
||||
<attributes>
|
||||
<embedded name="favouriteKnife" access="PROPERTY"/>
|
||||
</attributes>
|
||||
</entity>
|
||||
</entity-mappings>
|
|
@ -3,7 +3,6 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm file:/Users/hardy/work/hibernate/core/trunk/annotations/src/main/resources/org/hibernate/ejb/orm_2_0.xsd"
|
||||
version="2.0">
|
||||
<description>Mapping for Crew entity</description>
|
||||
<package>org.hibernate.test.annotations.access.xml</package>
|
||||
<mapped-superclass class="Crew" metadata-complete="false" access="FIELD">
|
||||
<attributes>
|
||||
|
|
Loading…
Reference in New Issue