Hibernate SVN: r19627 - in core/trunk/testing/src/main/java/org/hibernate: test/annotations and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-28 10:21:57 -0400 (Fri, 28 May 2010)
New Revision: 19627
Modified:
core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialect.java
core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java
core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
Log:
HHH-5204 Aligned the properties of SkipForDialect, RequiresDialect and RequiresDialectFeature
Modified: core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialect.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialect.java 2010-05-27 18:44:57 UTC (rev 19626)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialect.java 2010-05-28 14:21:57 UTC (rev 19627)
@@ -33,14 +33,15 @@
/**
* Annotation used to indicate that a test should be run only when run against the
* indicated dialects.
- *
+ *
* @author Hardy Ferentschik
*/
-(a)Target({ElementType.METHOD, ElementType.TYPE})
+@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiresDialect {
/**
* The dialects against which to run the test
+ *
* @return The dialects
*/
Class<? extends Dialect>[] value();
@@ -48,7 +49,22 @@
/**
* Used to indicate if the dialects should be matched strictly (classes equal) or
* non-strictly (instanceof).
+ *
* @return Should strict matching be used?
*/
boolean strictMatching() default false;
+
+ /**
+ * Comment describing the reason why the dialect is required.
+ *
+ * @return The comment
+ */
+ String comment() default "";
+
+ /**
+ * The key of a JIRA issue which relates this this restriction
+ *
+ * @return The jira issue key
+ */
+ String jiraKey() default "";
}
Modified: core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java 2010-05-27 18:44:57 UTC (rev 19626)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java 2010-05-28 14:21:57 UTC (rev 19627)
@@ -42,4 +42,18 @@
* @return The name of the dialect feature.
*/
Class<? extends DialectChecks> value();
+
+ /**
+ * Comment describing the reason why the feature is required.
+ *
+ * @return The comment
+ */
+ String comment() default "";
+
+ /**
+ * The key of a JIRA issue which relates this this feature requirement.
+ *
+ * @return The jira issue key
+ */
+ String jiraKey() default "";
}
\ No newline at end of file
Modified: core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-27 18:44:57 UTC (rev 19626)
+++ core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-28 14:21:57 UTC (rev 19627)
@@ -184,7 +184,7 @@
}
else {
if ( !dialectClass.isInstance( dialect ) ) {
- return buildSkip( dialect, null, null );
+ return buildSkip( dialect, requiresDialectAnn.comment(), requiresDialectAnn.jiraKey() );
}
}
}
@@ -197,7 +197,7 @@
DialectChecks check = checkClass.newInstance();
boolean skip = check.include( dialect );
if ( skip ) {
- return buildSkip( dialect, null, null );
+ return buildSkip( dialect, requiresDialectFeatureAnn.comment(), requiresDialectFeatureAnn.jiraKey() );
}
}
return null;
14 years, 7 months
Hibernate SVN: r19626 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/access/jpa and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-27 14:44:57 -0400 (Thu, 27 May 2010)
New Revision: 19626
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/Course8.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/InheritanceState.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyContainer.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessTest.java
Log:
HHH-5004 Fixed problems in PropertyContainer and added some more comments. Cleaned up some code in InheritanceState
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-05-26 22:27:27 UTC (rev 19625)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-05-27 18:44:57 UTC (rev 19626)
@@ -1341,7 +1341,6 @@
accessType = propertyContainer.getExplicitAccessStrategy();
}
- propertyContainer.assertTypesAreResolvable( accessType );
Collection<XProperty> properties = propertyContainer.getProperties( accessType );
for ( XProperty p : properties ) {
final int currentIdPropertyCounter = addProperty(
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/InheritanceState.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/InheritanceState.java 2010-05-26 22:27:27 UTC (rev 19625)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/InheritanceState.java 2010-05-27 18:44:57 UTC (rev 19626)
@@ -35,7 +35,6 @@
import javax.persistence.MappedSuperclass;
import org.hibernate.AnnotationException;
-import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XAnnotatedElement;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
@@ -49,7 +48,6 @@
*/
public class InheritanceState {
private XClass clazz;
- private XClass identifierType;
/**
* Has sibling (either mappedsuperclass entity)
@@ -75,7 +73,6 @@
this.setClazz( clazz );
this.mappings = mappings;
this.inheritanceStatePerClass = inheritanceStatePerClass;
- this.identifierType = mappings.getReflectionManager().toXClass( void.class ); //not initialized
extractInheritanceType();
}
@@ -115,7 +112,7 @@
return null;
}
- public static InheritanceState getSuperclassInheritanceState( XClass clazz, Map<XClass, InheritanceState> states) {
+ public static InheritanceState getSuperclassInheritanceState(XClass clazz, Map<XClass, InheritanceState> states) {
XClass superclass = clazz;
do {
superclass = superclass.getSuperclass();
@@ -171,7 +168,7 @@
void postProcess(PersistentClass persistenceClass, EntityBinder entityBinder) {
//make sure we run elements to process
getElementsToProcess();
- addMappedSuperClassInMetadata(persistenceClass);
+ addMappedSuperClassInMetadata( persistenceClass );
entityBinder.setPropertyAccessType( accessType );
}
@@ -184,8 +181,8 @@
}
else {
InheritanceState state = InheritanceState.getSuperclassInheritanceState( clazz, inheritanceStatePerClass );
- if (state != null){
- return state.getClassWithIdClass(true);
+ if ( state != null ) {
+ return state.getClassWithIdClass( true );
}
else {
return null;
@@ -194,14 +191,14 @@
}
public Boolean hasIdClassOrEmbeddedId() {
- if (hasIdClassOrEmbeddedId == null) {
+ if ( hasIdClassOrEmbeddedId == null ) {
hasIdClassOrEmbeddedId = false;
if ( getClassWithIdClass( true ) != null ) {
hasIdClassOrEmbeddedId = true;
}
else {
final ElementsToProcess process = getElementsToProcess();
- for(PropertyData property : process.getElements() ) {
+ for ( PropertyData property : process.getElements() ) {
if ( property.getProperty().isAnnotationPresent( EmbeddedId.class ) ) {
hasIdClassOrEmbeddedId = true;
break;
@@ -213,33 +210,40 @@
}
/*
- * Get the annotated elements, guessing the access type from @Id or @EmbeddedId presence.
- * Change EntityBinder by side effect
- */
+ * Get the annotated elements, guessing the access type from @Id or @EmbeddedId presence.
+ * Change EntityBinder by side effect
+ */
+
public ElementsToProcess getElementsToProcess() {
- if (elementsToProcess == null) {
+ if ( elementsToProcess == null ) {
InheritanceState inheritanceState = inheritanceStatePerClass.get( clazz );
assert !inheritanceState.isEmbeddableSuperclass();
getMappedSuperclassesTillNextEntityOrdered();
- accessType = determineDefaultAccessType( );
+ accessType = determineDefaultAccessType();
List<PropertyData> elements = new ArrayList<PropertyData>();
int deep = classesToProcessForMappedSuperclass.size();
int idPropertyCount = 0;
for ( int index = 0; index < deep; index++ ) {
- PropertyContainer propertyContainer = new PropertyContainer( classesToProcessForMappedSuperclass.get( index ), clazz );
- int currentIdPropertyCount = AnnotationBinder.addElementsOfClass( elements, accessType, propertyContainer, mappings );
- idPropertyCount += currentIdPropertyCount;
+ PropertyContainer propertyContainer = new PropertyContainer(
+ classesToProcessForMappedSuperclass.get(
+ index
+ ), clazz
+ );
+ int currentIdPropertyCount = AnnotationBinder.addElementsOfClass(
+ elements, accessType, propertyContainer, mappings
+ );
+ idPropertyCount += currentIdPropertyCount;
}
if ( idPropertyCount == 0 && !inheritanceState.hasParents() ) {
throw new AnnotationException( "No identifier specified for entity: " + clazz.getName() );
}
- elementsToProcess = new ElementsToProcess( elements, idPropertyCount);
+ elementsToProcess = new ElementsToProcess( elements, idPropertyCount );
}
return elementsToProcess;
}
@@ -251,25 +255,19 @@
for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) {
final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
- if (isEmbeddedId) {
- identifierType = prop.getClassOrElementClass();
- }
return AccessType.PROPERTY;
}
}
for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) {
final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
- if ( isEmbeddedId ) {
- identifierType = prop.getClassOrElementClass();
- }
return AccessType.FIELD;
}
}
}
xclass = xclass.getSuperclass();
}
- throw new AnnotationException( "No identifier specified for entity: " + clazz.getName() );
+ throw new AnnotationException( "No identifier specified for entity: " + clazz );
}
private void getMappedSuperclassesTillNextEntityOrdered() {
@@ -303,19 +301,20 @@
mappings.getClass( superEntityState.getClazz().getName() ) :
null;
final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1;
- for ( int index = 0 ; index < lastMappedSuperclass ; index++ ) {
+ for ( int index = 0; index < lastMappedSuperclass; index++ ) {
org.hibernate.mapping.MappedSuperclass parentSuperclass = mappedSuperclass;
- final Class<?> type = mappings.getReflectionManager().toClass( classesToProcessForMappedSuperclass.get( index ) );
+ final Class<?> type = mappings.getReflectionManager()
+ .toClass( classesToProcessForMappedSuperclass.get( index ) );
//add MAppedSuperclass if not already there
mappedSuperclass = mappings.getMappedSuperclass( type );
- if (mappedSuperclass == null) {
- mappedSuperclass = new org.hibernate.mapping.MappedSuperclass(parentSuperclass, superEntity );
+ if ( mappedSuperclass == null ) {
+ mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity );
mappedSuperclass.setMappedClass( type );
mappings.addMappedSuperclass( type, mappedSuperclass );
}
}
- if (mappedSuperclass != null) {
- persistentClass.setSuperMappedSuperclass(mappedSuperclass);
+ if ( mappedSuperclass != null ) {
+ persistentClass.setSuperMappedSuperclass( mappedSuperclass );
}
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyContainer.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyContainer.java 2010-05-26 22:27:27 UTC (rev 19625)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyContainer.java 2010-05-27 18:44:57 UTC (rev 19626)
@@ -24,9 +24,10 @@
*/
package org.hibernate.cfg;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.TreeMap;
import javax.persistence.Access;
import javax.persistence.ManyToMany;
@@ -55,19 +56,40 @@
class PropertyContainer {
private static final Logger log = LoggerFactory.getLogger( AnnotationBinder.class );
- private final XClass entityAtStake;
+
+ private final AccessType explicitClassDefinedAccessType;
+
+ /**
+ * Constains the properties which must be returned in case the class is accessed via {@code AccessType.FIELD}. Note,
+ * this does not mean that all {@code XProperty}s in this map are fields. Due to JPA access rules single properties
+ * can have different access type than the overall class access type.
+ */
private final TreeMap<String, XProperty> fieldAccessMap;
+
+ /**
+ * Constains the properties which must be returned in case the class is accessed via {@code AccessType.Property}. Note,
+ * this does not mean that all {@code XProperty}s in this map are properties/methods. Due to JPA access rules single properties
+ * can have different access type than the overall class access type.
+ */
private final TreeMap<String, XProperty> propertyAccessMap;
+
+ /**
+ * The class for which this container is created.
+ */
private final XClass xClass;
- private final AccessType explicitClassDefinedAccessType;
+ private final XClass entityAtStake;
PropertyContainer(XClass clazz, XClass entityAtStake) {
this.xClass = clazz;
this.entityAtStake = entityAtStake;
+
+ explicitClassDefinedAccessType = determineClassDefinedAccessStrategy();
+
+ // first add all properties to field and property map
fieldAccessMap = initProperties( AccessType.FIELD );
propertyAccessMap = initProperties( AccessType.PROPERTY );
- explicitClassDefinedAccessType = determineClassDefinedAccessStrategy();
- checkForJpaAccess();
+
+ considerExplicitFieldAndPropertyAccess();
}
public XClass getEntityAtStake() {
@@ -87,16 +109,17 @@
}
public Collection<XProperty> getProperties(AccessType accessType) {
+ assertTypesAreResolvable( accessType );
if ( AccessType.DEFAULT == accessType || AccessType.PROPERTY == accessType ) {
- return propertyAccessMap.values();
+ return Collections.unmodifiableCollection( propertyAccessMap.values() );
}
else {
- return fieldAccessMap.values();
+ return Collections.unmodifiableCollection( fieldAccessMap.values() );
}
}
- public void assertTypesAreResolvable(AccessType access) {
- TreeMap<String, XProperty> xprops;
+ private void assertTypesAreResolvable(AccessType access) {
+ Map<String, XProperty> xprops;
if ( AccessType.PROPERTY.equals( access ) || AccessType.DEFAULT.equals( access ) ) {
xprops = propertyAccessMap;
}
@@ -113,29 +136,25 @@
}
}
- private void checkForJpaAccess() {
- List<XProperty> tmpList = new ArrayList<XProperty>();
+ private void considerExplicitFieldAndPropertyAccess() {
for ( XProperty property : fieldAccessMap.values() ) {
Access access = property.getAnnotation( Access.class );
if ( access == null ) {
continue;
}
+ // see "2.3.2 Explicit Access Type" of JPA 2 spec
+ // the access type for this property is explicitly set to AccessType.FIELD, hence we have to
+ // use field access for this property even if the default access type for the class is AccessType.PROPERTY
AccessType accessType = AccessType.getAccessStrategy( access.value() );
- if ( accessType == AccessType.PROPERTY ) {
+ if ( accessType == AccessType.FIELD ) {
+ propertyAccessMap.put( property.getName(), property );
+ }
+ else { // AccessType.PROPERTY
log.warn( "Placing @Access(AccessType.PROPERTY) on a field does not have any effect." );
- continue;
}
-
- tmpList.add( property );
}
- for ( XProperty property : tmpList ) {
- fieldAccessMap.remove( property.getName() );
- propertyAccessMap.put( property.getName(), property );
- }
-
- tmpList.clear();
for ( XProperty property : propertyAccessMap.values() ) {
Access access = property.getAnnotation( Access.class );
if ( access == null ) {
@@ -143,20 +162,32 @@
}
AccessType accessType = AccessType.getAccessStrategy( access.value() );
- if ( accessType == AccessType.FIELD ) {
- log.warn( "Placing @Access(AccessType.FIELD) on a field does not have any effect." );
- continue;
+
+ // see "2.3.2 Explicit Access Type" of JPA 2 spec
+ // the access type for this property is explicitly set to AccessType.PROPERTY, hence we have to
+ // return use method access even if the default class access type is AccessType.FIELD
+ if ( accessType == AccessType.PROPERTY ) {
+ fieldAccessMap.put( property.getName(), property );
}
-
- tmpList.add( property );
+ else { // AccessType.FIELD
+ log.warn( "Placing @Access(AccessType.FIELD) on a property does not have any effect." );
+ }
}
- for ( XProperty property : tmpList ) {
- propertyAccessMap.remove( property.getName() );
- fieldAccessMap.put( property.getName(), property );
- }
}
+ /**
+ * Retrieves all properties from the {@code xClass} with the specified access type. This method does not take
+ * any jpa access rules/annotations into account yet.
+ *
+ * @param access The access type - {@code AccessType.FIELD} or {@code AccessType.Property}
+ *
+ * @return A maps of the properties with the given access type keyed against their property name
+ */
private TreeMap<String, XProperty> initProperties(AccessType access) {
+ if ( !( AccessType.PROPERTY.equals( access ) || AccessType.FIELD.equals( access ) ) ) {
+ throw new IllegalArgumentException( "Acces type has to be AccessType.FIELD or AccessType.Property" );
+ }
+
//order so that property are used in the same order when binding native query
TreeMap<String, XProperty> propertiesMap = new TreeMap<String, XProperty>();
List<XProperty> properties = xClass.getDeclaredProperties( access.getType() );
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java 2010-05-26 22:27:27 UTC (rev 19625)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java 2010-05-27 18:44:57 UTC (rev 19626)
@@ -192,4 +192,14 @@
tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
);
}
+
+ /**
+ * HHH-5004
+ */
+ public void testAccessOnClassAndId() throws Exception {
+ AnnotationConfiguration cfg = new AnnotationConfiguration();
+ cfg.addAnnotatedClass( Course8.class );
+ cfg.addAnnotatedClass( Student.class );
+ cfg.buildSessionFactory();
+ }
}
\ No newline at end of file
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessTest.java 2010-05-26 22:27:27 UTC (rev 19625)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/AccessTest.java 2010-05-27 18:44:57 UTC (rev 19626)
@@ -34,6 +34,7 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class AccessTest extends TestCase {
Copied: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/Course8.java (from rev 19610, core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/Course7.java)
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/Course8.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/jpa/Course8.java 2010-05-27 18:44:57 UTC (rev 19626)
@@ -0,0 +1,78 @@
+//$Id: AccessTest.java 15025 2008-08-11 09:14:39Z hardy.ferentschik $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.access.jpa;
+
+import java.util.List;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+
+/**
+ * Test class for HHH-5004
+ *
+ * @author Hardy Ferentschik
+ */
+@Entity
+(a)Access(AccessType.PROPERTY)
+public class Course8 {
+ private long id;
+
+ private String title;
+
+ private List<Student> students;
+
+ @Id
+ @GeneratedValue
+ @Access(AccessType.PROPERTY)
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @OneToMany(cascade = CascadeType.ALL)
+ public List<Student> getStudents() {
+ return students;
+ }
+
+ public void setStudents(List<Student> students) {
+ this.students = students;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+}
\ No newline at end of file
14 years, 7 months
Hibernate SVN: r19625 - core/trunk/parent.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-26 18:27:27 -0400 (Wed, 26 May 2010)
New Revision: 19625
Modified:
core/trunk/parent/pom.xml
Log:
HHH-4868 - Upgrade to Javassist 3.12.0.GA
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2010-05-26 22:08:33 UTC (rev 19624)
+++ core/trunk/parent/pom.xml 2010-05-26 22:27:27 UTC (rev 19625)
@@ -508,7 +508,7 @@
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
- <version>3.9.0.GA</version>
+ <version>3.12.0.GA</version>
</dependency>
<!-- cglib is optional, but if defined it should be version 2.2 -->
<dependency>
14 years, 7 months
Hibernate SVN: r19624 - in core/trunk/core/src: test/java/org/hibernate and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-26 18:08:33 -0400 (Wed, 26 May 2010)
New Revision: 19624
Added:
core/trunk/core/src/test/java/org/hibernate/property/
core/trunk/core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java
Modified:
core/trunk/core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java
Log:
HHH-2268 - Skip bridge methods during getter determination (JDK Bug 5062759)
Modified: core/trunk/core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java 2010-05-26 21:31:54 UTC (rev 19623)
+++ core/trunk/core/src/main/java/org/hibernate/property/BasicPropertyAccessor.java 2010-05-26 22:08:33 UTC (rev 19624)
@@ -63,7 +63,7 @@
public void set(Object target, Object value, SessionFactoryImplementor factory)
throws HibernateException {
try {
- method.invoke( target, new Object[] { value } );
+ method.invoke( target, value );
}
catch (NullPointerException npe) {
if ( value==null && method.getParameterTypes()[0].isPrimitive() ) {
@@ -169,7 +169,7 @@
*/
public Object get(Object target) throws HibernateException {
try {
- return method.invoke(target, null);
+ return method.invoke( target, (Object[]) null );
}
catch (InvocationTargetException ite) {
throw new PropertyAccessException(
@@ -299,15 +299,15 @@
Method[] methods = theClass.getDeclaredMethods();
Method potentialSetter = null;
- for (int i=0; i<methods.length; i++) {
- String methodName = methods[i].getName();
+ for ( Method method : methods ) {
+ final String methodName = method.getName();
- if ( methods[i].getParameterTypes().length==1 && methodName.startsWith("set") ) {
- String testStdMethod = Introspector.decapitalize( methodName.substring(3) );
- String testOldMethod = methodName.substring(3);
- if ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) {
- potentialSetter = methods[i];
- if ( returnType==null || methods[i].getParameterTypes()[0].equals(returnType) ) {
+ if ( method.getParameterTypes().length == 1 && methodName.startsWith( "set" ) ) {
+ String testStdMethod = Introspector.decapitalize( methodName.substring( 3 ) );
+ String testOldMethod = methodName.substring( 3 );
+ if ( testStdMethod.equals( propertyName ) || testOldMethod.equals( propertyName ) ) {
+ potentialSetter = method;
+ if ( returnType == null || method.getParameterTypes()[0].equals( returnType ) ) {
return potentialSetter;
}
}
@@ -316,13 +316,11 @@
return potentialSetter;
}
- public Getter getGetter(Class theClass, String propertyName)
- throws PropertyNotFoundException {
+ public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
return createGetter(theClass, propertyName);
}
- public static Getter createGetter(Class theClass, String propertyName)
- throws PropertyNotFoundException {
+ public static Getter createGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
BasicGetter result = getGetterOrNull(theClass, propertyName);
if (result==null) {
throw new PropertyNotFoundException(
@@ -333,17 +331,19 @@
);
}
return result;
-
}
private static BasicGetter getGetterOrNull(Class theClass, String propertyName) {
+ if (theClass==Object.class || theClass==null) {
+ return null;
+ }
- if (theClass==Object.class || theClass==null) return null;
-
Method method = getterMethod(theClass, propertyName);
if (method!=null) {
- if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
+ if ( !ReflectHelper.isPublic(theClass, method) ) {
+ method.setAccessible(true);
+ }
return new BasicGetter(theClass, method, propertyName);
}
else {
@@ -359,33 +359,38 @@
}
private static Method getterMethod(Class theClass, String propertyName) {
-
Method[] methods = theClass.getDeclaredMethods();
- for (int i=0; i<methods.length; i++) {
- // only carry on if the method has no parameters
- if ( methods[i].getParameterTypes().length == 0 ) {
- String methodName = methods[i].getName();
+ for ( Method method : methods ) {
+ // if the method has parameters, skip it
+ if ( method.getParameterTypes().length != 0 ) {
+ continue;
+ }
+ // if the method is a "bridge", skip it
+ if ( method.isBridge() ) {
+ continue;
+ }
- // try "get"
- if ( methodName.startsWith("get") ) {
- String testStdMethod = Introspector.decapitalize( methodName.substring(3) );
- String testOldMethod = methodName.substring(3);
- if ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) {
- return methods[i];
- }
+ final String methodName = method.getName();
+ // try "get"
+ if ( methodName.startsWith( "get" ) ) {
+ String testStdMethod = Introspector.decapitalize( methodName.substring( 3 ) );
+ String testOldMethod = methodName.substring( 3 );
+ if ( testStdMethod.equals( propertyName ) || testOldMethod.equals( propertyName ) ) {
+ return method;
}
+ }
- // if not "get", then try "is"
- if ( methodName.startsWith("is") ) {
- String testStdMethod = Introspector.decapitalize( methodName.substring(2) );
- String testOldMethod = methodName.substring(2);
- if ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) {
- return methods[i];
- }
+ // if not "get", then try "is"
+ if ( methodName.startsWith( "is" ) ) {
+ String testStdMethod = Introspector.decapitalize( methodName.substring( 2 ) );
+ String testOldMethod = methodName.substring( 2 );
+ if ( testStdMethod.equals( propertyName ) || testOldMethod.equals( propertyName ) ) {
+ return method;
}
}
}
+
return null;
}
Added: core/trunk/core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java 2010-05-26 22:08:33 UTC (rev 19624)
@@ -0,0 +1,103 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.property;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class BasicPropertyAccessorTest extends TestCase {
+ public static abstract class Super {
+ public abstract Object getIt();
+ public abstract void setIt(Object it);
+ }
+
+ public static class Duper extends Super {
+ private String it;
+
+ public Duper(String it) {
+ this.it = it;
+ }
+
+ public String getIt() {
+ return it;
+ }
+
+ @Override
+ public void setIt(Object it) {
+ this.it = ( it == null || String.class.isInstance( it ) )
+ ? (String) it
+ : it.toString();
+ }
+ }
+
+ public static class Duper2 extends Super {
+ private String it;
+
+ public Duper2(String it) {
+ this.it = it;
+ }
+
+ public String getIt() {
+ return it;
+ }
+
+ public void setIt(String it) {
+ this.it = it;
+ }
+
+ @Override
+ public void setIt(Object it) {
+ if ( it == null || String.class.isInstance( it ) ) {
+ setIt( (String) it );
+ }
+ else {
+ setIt( it.toString() );
+ }
+ }
+ }
+
+ public void testBridgeMethodDisregarded() {
+ BasicPropertyAccessor accessor = new BasicPropertyAccessor();
+
+ {
+ BasicPropertyAccessor.BasicGetter getter = (BasicPropertyAccessor.BasicGetter) accessor.getGetter( Duper.class, "it" );
+ assertEquals( String.class, getter.getReturnType() );
+
+ BasicPropertyAccessor.BasicSetter setter = (BasicPropertyAccessor.BasicSetter) accessor.getSetter( Duper.class, "it" );
+ assertEquals( Object.class, setter.getMethod().getParameterTypes()[0] );
+ }
+
+ {
+ BasicPropertyAccessor.BasicGetter getter = (BasicPropertyAccessor.BasicGetter) accessor.getGetter( Duper2.class, "it" );
+ assertEquals( String.class, getter.getReturnType() );
+
+ BasicPropertyAccessor.BasicSetter setter = (BasicPropertyAccessor.BasicSetter) accessor.getSetter( Duper2.class, "it" );
+ assertEquals( String.class, setter.getMethod().getParameterTypes()[0] );
+ }
+ }
+}
14 years, 7 months
Hibernate SVN: r19623 - in core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid: keymanytoone and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-26 17:31:54 -0400 (Wed, 26 May 2010)
New Revision: 19623
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Card.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/CardField.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/EagerKeyManyToOneTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Key.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/PrimaryKey.java
Log:
HHH-4147 - Eager Bidirectional association with @ManyToOne in PK lead to infinite loop
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Card.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Card.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Card.java 2010-05-26 21:31:54 UTC (rev 19623)
@@ -0,0 +1,77 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.cid.keymanytoone;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class Card implements Serializable {
+ @Id
+ private String id;
+
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "primaryKey.card")
+ private Set<CardField> fields;
+
+ public Card(String id) {
+ this();
+ this.id = id;
+
+ }
+
+ Card() {
+ fields = new HashSet<CardField>();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void addField(Card card, Key key) {
+ fields.add(new CardField(card, key));
+ }
+
+ public Set<CardField> getFields() {
+ return fields;
+ }
+
+ public void setFields(Set<CardField> fields) {
+ this.fields = fields;
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/CardField.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/CardField.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/CardField.java 2010-05-26 21:31:54 UTC (rev 19623)
@@ -0,0 +1,56 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.cid.keymanytoone;
+
+import java.io.Serializable;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class CardField implements Serializable {
+
+ @EmbeddedId
+ private PrimaryKey primaryKey;
+
+ CardField(Card card, Key key) {
+ this.primaryKey = new PrimaryKey(card, key);
+ }
+
+ CardField() {
+ }
+
+ public PrimaryKey getPrimaryKey() {
+ return primaryKey;
+ }
+
+ public void setPrimaryKey(PrimaryKey primaryKey) {
+ this.primaryKey = primaryKey;
+ }
+}
+
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/EagerKeyManyToOneTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/EagerKeyManyToOneTest.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/EagerKeyManyToOneTest.java 2010-05-26 21:31:54 UTC (rev 19623)
@@ -0,0 +1,89 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.cid.keymanytoone;
+
+import org.hibernate.Session;
+import org.hibernate.test.annotations.TestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EagerKeyManyToOneTest extends TestCase {
+ public static final String CARD_ID = "cardId";
+ public static final String KEY_ID = "keyId";
+
+ @Override
+ protected Class<?>[] getAnnotatedClasses() {
+ return new Class[] { Card.class, CardField.class, Key.class, PrimaryKey.class };
+ }
+
+ public void testLoadEntityWithEagerFetchingToKeyManyToOneReferenceBackToSelf() {
+ // based on the core testsuite test of same name in org.hibernate.test.keymanytoone.bidir.component.EagerKeyManyToOneTest
+ // meant to test against regression relating to http://opensource.atlassian.com/projects/hibernate/browse/HHH-2277
+ // and http://opensource.atlassian.com/projects/hibernate/browse/HHH-4147
+
+ {
+ Session s = openSession();
+ s.beginTransaction();
+ Card card = new Card( CARD_ID );
+ Key key = new Key( KEY_ID );
+ card.addField( card, key );
+ s.persist( key );
+ s.persist( card );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ {
+ Session s = openSession();
+ s.beginTransaction();
+ try {
+ Card card = (Card) s.get( Card.class, CARD_ID );
+ assertEquals( 1, card.getFields().size() );
+ CardField cf = card.getFields().iterator().next();
+ assertSame( card, cf.getPrimaryKey().getCard() );
+ }
+ catch ( StackOverflowError soe ) {
+ fail( "eager + key-many-to-one caused stack-overflow in annotations" );
+ }
+ finally {
+ s.getTransaction().commit();
+ s.close();
+ }
+ }
+
+ {
+ Session s = openSession();
+ s.beginTransaction();
+ Card card = (Card) s.get( Card.class, CARD_ID );
+ Key key = (Key) s.get( Key.class, KEY_ID );
+ s.delete( card );
+ s.delete( key );
+ s.getTransaction().commit();
+ s.close();
+ }
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Key.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Key.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/Key.java 2010-05-26 21:31:54 UTC (rev 19623)
@@ -0,0 +1,54 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.cid.keymanytoone;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class Key implements Serializable {
+ @Id
+ private String id;
+
+ public Key(String id) {
+ this.id = id;
+ }
+
+ Key() {
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/PrimaryKey.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/PrimaryKey.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/keymanytoone/PrimaryKey.java 2010-05-26 21:31:54 UTC (rev 19623)
@@ -0,0 +1,66 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.cid.keymanytoone;
+
+import java.io.Serializable;
+import javax.persistence.Embeddable;
+import javax.persistence.ManyToOne;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Embeddable
+public class PrimaryKey implements Serializable {
+ @ManyToOne(optional = false)
+ private Card card;
+
+ @ManyToOne(optional = false)
+ private Key key;
+
+ public PrimaryKey(Card card, Key key) {
+ this.card = card;
+ this.key = key;
+ }
+
+ PrimaryKey() {
+ }
+
+ public Card getCard() {
+ return card;
+ }
+
+ public void setCard(Card card) {
+ this.card = card;
+ }
+
+ public Key getKey() {
+ return key;
+ }
+
+ public void setKey(Key key) {
+ this.key = key;
+ }
+}
14 years, 7 months
Hibernate SVN: r19622 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-05-26 12:22:31 -0400 (Wed, 26 May 2010)
New Revision: 19622
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
Log:
HHH-5149 mark multiple mapping of the same entity as XML only
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:21:56 UTC (rev 19621)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:22:31 UTC (rev 19622)
@@ -5378,6 +5378,10 @@
<para>Associations are now specified using <literal>entity-name</literal>
instead of <literal>class</literal>.</para>
+
+ <note>
+ <para>This feature is not supported in Annotations</para>
+ </note>
</section>
<section id="mapping-quotedidentifiers">
14 years, 7 months
Hibernate SVN: r19621 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-05-26 12:21:56 -0400 (Wed, 26 May 2010)
New Revision: 19621
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
Log:
HHH-5149 Merge doc for generated properties and quoted elements
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:21:22 UTC (rev 19620)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:21:56 UTC (rev 19621)
@@ -5389,7 +5389,13 @@
<literal>Dialect</literal>. This is usually double quotes, but the SQL
Server uses brackets and MySQL uses backticks.</para>
- <programlisting role="XML"><class name="LineItem" table="`Line Item`">
+ <programlisting role="XML">@Entity @Table(name="`Line Item`")
+class LineItem {
+ @id @Column(name="`Item Id`") Integer id;
+ @Column(name="`Item #`") int itemNumber
+}
+
+<class name="LineItem" table="`Line Item`">
<id name="id" column="`Item Id`"/><generator class="assigned"/></id>
<property name="itemNumber" column="`Item #`"/>
...
@@ -5427,6 +5433,9 @@
<para><literal>always</literal>: the property value is generated both on
insert and on update.</para>
+
+ <para>To mark a property as generated, use
+ <classname>@Generated</classname>.</para>
</section>
<section id="mapping-column-read-and-write" revision="1">
@@ -5460,6 +5469,10 @@
<para>The <literal>write</literal> expression, if specified, must contain
exactly one '?' placeholder for the value.</para>
+
+ <note>
+ <para>This feature is not supported in Annotations</para>
+ </note>
</section>
<section id="mapping-database-object">
@@ -5509,5 +5522,9 @@
<dialect-scope name="org.hibernate.dialect.Oracle10gDialect"/>
</database-object>
</hibernate-mapping></programlisting>
+
+ <note>
+ <para>This feature is not supported in Annotations</para>
+ </note>
</section>
</chapter>
14 years, 7 months
Hibernate SVN: r19620 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-05-26 12:21:22 -0400 (Wed, 26 May 2010)
New Revision: 19620
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
Log:
HHH-5149 remove alternative mapping section
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:20:43 UTC (rev 19619)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:21:22 UTC (rev 19620)
@@ -5396,181 +5396,6 @@
</class></programlisting>
</section>
- <section id="mapping-alternatives">
- <title>Metadata alternatives</title>
-
- <para>XML does not suit all users so there are some alternative ways to
- define O/R mapping metadata in Hibernate.</para>
-
- <section id="mapping-xdoclet">
- <title>Using XDoclet markup</title>
-
- <para>Many Hibernate users prefer to embed mapping information directly
- in sourcecode using XDoclet <literal>@hibernate.tags</literal>. We do
- not cover this approach in this reference guide since it is considered
- part of XDoclet. However, we include the following example of the
- <literal>Cat</literal> class with XDoclet mappings:</para>
-
- <programlisting role="JAVA">package eg;
-import java.util.Set;
-import java.util.Date;
-
-/**
- * @hibernate.class
- * table="CATS"
- */
-public class Cat {
- private Long id; // identifier
- private Date birthdate;
- private Cat mother;
- private Set kittens
- private Color color;
- private char sex;
- private float weight;
-
- /*
- * @hibernate.id
- * generator-class="native"
- * column="CAT_ID"
- */
- public Long getId() {
- return id;
- }
- private void setId(Long id) {
- this.id=id;
- }
-
- /**
- * @hibernate.many-to-one
- * column="PARENT_ID"
- */
- public Cat getMother() {
- return mother;
- }
- void setMother(Cat mother) {
- this.mother = mother;
- }
-
- /**
- * @hibernate.property
- * column="BIRTH_DATE"
- */
- public Date getBirthdate() {
- return birthdate;
- }
- void setBirthdate(Date date) {
- birthdate = date;
- }
- /**
- * @hibernate.property
- * column="WEIGHT"
- */
- public float getWeight() {
- return weight;
- }
- void setWeight(float weight) {
- this.weight = weight;
- }
-
- /**
- * @hibernate.property
- * column="COLOR"
- * not-null="true"
- */
- public Color getColor() {
- return color;
- }
- void setColor(Color color) {
- this.color = color;
- }
- /**
- * @hibernate.set
- * inverse="true"
- * order-by="BIRTH_DATE"
- * @hibernate.collection-key
- * column="PARENT_ID"
- * @hibernate.collection-one-to-many
- */
- public Set getKittens() {
- return kittens;
- }
- void setKittens(Set kittens) {
- this.kittens = kittens;
- }
- // addKitten not needed by Hibernate
- public void addKitten(Cat kitten) {
- kittens.add(kitten);
- }
-
- /**
- * @hibernate.property
- * column="SEX"
- * not-null="true"
- * update="false"
- */
- public char getSex() {
- return sex;
- }
- void setSex(char sex) {
- this.sex=sex;
- }
-}</programlisting>
-
- <para>See the Hibernate website for more examples of XDoclet and
- Hibernate.</para>
- </section>
-
- <section id="mapping-annotations" revision="2">
- <title>Using JDK 5.0 Annotations</title>
-
- <para>JDK 5.0 introduced XDoclet-style annotations at the language level
- that are type-safe and checked at compile time. This mechanism is more
- powerful than XDoclet annotations and better supported by tools and
- IDEs. IntelliJ IDEA, for example, supports auto-completion and syntax
- highlighting of JDK 5.0 annotations. The new revision of the EJB
- specification (JSR-220) uses JDK 5.0 annotations as the primary metadata
- mechanism for entity beans. Hibernate3 implements the
- <literal>EntityManager</literal> of JSR-220 (the persistence API).
- Support for mapping metadata is available via the <emphasis>Hibernate
- Annotations</emphasis> package as a separate download. Both EJB3
- (JSR-220) and Hibernate3 metadata is supported.</para>
-
- <para>This is an example of a POJO class annotated as an EJB entity
- bean:</para>
-
- <programlisting role="JAVA">@Entity(access = AccessType.FIELD)
-public class Customer implements Serializable {
-
- @Id;
- Long id;
-
- String firstName;
- String lastName;
- Date birthday;
-
- @Transient
- Integer age;
-
- @Embedded
- private Address homeAddress;
-
- @OneToMany(cascade=CascadeType.ALL)
- @JoinColumn(name="CUSTOMER_ID")
- Set<Order> orders;
-
- // Getter/setter and business methods
-}</programlisting>
-
- <note>
- <title>Note</title>
-
- <para>Support for JDK 5.0 Annotations (and JSR-220) is currently under
- development. Please refer to the Hibernate Annotations module for more
- details.</para>
- </note>
- </section>
- </section>
-
<section id="mapping-generated" revision="1">
<title>Generated properties</title>
14 years, 7 months
Hibernate SVN: r19619 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-05-26 12:20:43 -0400 (Wed, 26 May 2010)
New Revision: 19619
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
Log:
HHH-5149 Merge embedded object / component documentations
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:20:08 UTC (rev 19618)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-26 16:20:43 UTC (rev 19619)
@@ -4572,14 +4572,115 @@
</itemizedlist>
</section>
- <section id="mapping-declaration-component" revision="2">
- <title>Component and dynamic-component</title>
+ <section id="mapping-declaration-component">
+ <title>Embedded objects (aka components)</title>
- <para>The <literal><component></literal> element maps properties
- of a child object to columns of the table of a parent class. Components
- can, in turn, declare their own properties, components or collections.
- See the "Component" examples below:</para>
+ <para>Embeddable objects (or components) are objects whose properties
+ are mapped to the same table as the owning entity's table. Components
+ can, in turn, declare their own properties, components or
+ collections</para>
+ <para>It is possible to declare an embedded component inside an entity
+ and even override its column mapping. Component classes have to be
+ annotated at the class level with the <literal>@Embeddable</literal>
+ annotation. It is possible to override the column mapping of an embedded
+ object for a particular entity using the <literal>@Embedded</literal>
+ and <literal>@AttributeOverride</literal> annotation in the associated
+ property:</para>
+
+ <programlisting language="JAVA" role="JAVA">@Entity
+public class Person implements Serializable {
+
+ // Persistent component using defaults
+ Address homeAddress;
+
+ @Embedded
+ @AttributeOverrides( {
+ @AttributeOverride(name="iso2", column = @Column(name="bornIso2") ),
+ @AttributeOverride(name="name", column = @Column(name="bornCountryName") )
+ } )
+ Country bornIn;
+ ...
+} </programlisting>
+
+ <programlisting language="JAVA" role="JAVA">@Embeddable
+public class Address implements Serializable {
+ String city;
+ Country nationality; //no overriding here
+} </programlisting>
+
+ <programlisting language="JAVA" role="JAVA">@Embeddable
+public class Country implements Serializable {
+ private String iso2;
+ @Column(name="countryName") private String name;
+
+ public String getIso2() { return iso2; }
+ public void setIso2(String iso2) { this.iso2 = iso2; }
+
+
+ public String getName() { return name; }
+ public void setName(String name) { this.name = name; }
+ ...
+} </programlisting>
+
+ <para>An embeddable object inherits the access type of its owning entity
+ (note that you can override that using the <literal>@Access</literal>
+ annotation).</para>
+
+ <para>The <literal>Person</literal> entity has two component properties,
+ <literal>homeAddress</literal> and <literal>bornIn</literal>.
+ <literal>homeAddress</literal> property has not been annotated, but
+ Hibernate will guess that it is a persistent component by looking for
+ the <literal>@Embeddable</literal> annotation in the Address class. We
+ also override the mapping of a column name (to
+ <literal>bornCountryName</literal>) with the
+ <literal>@Embedded</literal> and <literal>@AttributeOverride
+ </literal>annotations for each mapped attribute of
+ <literal>Country</literal>. As you can see, <literal>Country
+ </literal>is also a nested component of <literal>Address</literal>,
+ again using auto-detection by Hibernate and JPA defaults. Overriding
+ columns of embedded objects of embedded objects is through dotted
+ expressions.</para>
+
+ <programlisting language="JAVA" role="JAVA"> @Embedded
+ @AttributeOverrides( {
+ @AttributeOverride(name="city", column = @Column(name="fld_city") ),
+ @AttributeOverride(name="nationality.iso2", column = @Column(name="nat_Iso2") ),
+ @AttributeOverride(name="nationality.name", column = @Column(name="nat_CountryName") )
+ //nationality columns in homeAddress are overridden
+ } )
+ Address homeAddress;</programlisting>
+
+ <para>Hibernate Annotations supports something that is not explicitly
+ supported by the JPA specification. You can annotate a embedded object
+ with the <literal>@MappedSuperclass</literal> annotation to make the
+ superclass properties persistent (see
+ <literal>@MappedSuperclass</literal> for more informations).</para>
+
+ <para>You can also use association annotations in an embeddable object
+ (ie <literal>@OneToOne</literal>, <classname>@ManyToOne</classname>,
+ <classname>@OneToMany</classname> or <literal>@ManyToMany</literal>). To
+ override the association columns you can use
+ <literal>@AssociationOverride</literal>.</para>
+
+ <para>If you want to have the same embeddable object type twice in the
+ same entity, the column name defaulting will not work as several
+ embedded objects would share the same set of columns. In plain JPA, you
+ need to override at least one set of columns. Hibernate, however, allows
+ you to enhance the default naming mechanism through the
+ <classname>NamingStrategy</classname> interface. You can write a
+ strategy that prevent name clashing in such a situation.
+ <classname>DefaultComponentSafeNamingStrategy</classname> is an example
+ of this.</para>
+
+ <para>If a property of the embedded object points back to the owning
+ entity, annotate it with the <classname>@Parent</classname> annotation.
+ Hibernate will make sure this property is properly loaded with the
+ entity reference.</para>
+
+ <para>In XML, use the <literal><component></literal>
+ element.</para>
+
<programlistingco role="XML">
<areaspec>
<area coords="2" id="component1" />
@@ -4676,7 +4777,8 @@
<para>The <literal><dynamic-component></literal> element allows a
<literal>Map</literal> to be mapped as a component, where the property
names refer to keys of the map. See <xref
- linkend="components-dynamic" /> for more information.</para>
+ linkend="components-dynamic" /> for more information. This feature is
+ not supported in annotations.</para>
</section>
<section id="mapping-declaration-properties" revision="2">
14 years, 7 months