[hibernate-commits] Hibernate SVN: r14385 - in annotations/trunk/src: test/org/hibernate/test/annotations/generics and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Mar 3 22:37:29 EST 2008


Author: epbernard
Date: 2008-03-03 22:37:29 -0500 (Mon, 03 Mar 2008)
New Revision: 14385

Added:
   annotations/trunk/src/test/org/hibernate/test/annotations/generics/Dummy.java
Removed:
   annotations/trunk/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java
Modified:
   annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
   annotations/trunk/src/test/org/hibernate/test/annotations/generics/GenericsTest.java
Log:
ANN-698 ignore unbound property if default field access is used.

Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java	2008-03-04 02:07:51 UTC (rev 14384)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java	2008-03-04 03:37:29 UTC (rev 14385)
@@ -848,19 +848,32 @@
 		String accessType = explicitAccessType != null ?
 				explicitAccessType :
 				"property";
+		/*
+		 * delay the exception in case field access is used
+		 */
+		AnnotationException exceptionWhileWalkingElements = null;
+		try {
+			for (int index = 0; index < deep; index++) {
+				XClass clazz = classesToProcess.get( index );
 
-		for (int index = 0; index < deep; index++) {
-			XClass clazz = classesToProcess.get( index );
-
-			boolean currentHasIdentifier = addElementsOfAClass(
-					elements, propertyHolder, isPropertyAnnotated,
-					accessType, clazz, mappings
-			);
-			hasIdentifier = hasIdentifier || currentHasIdentifier;
+				boolean currentHasIdentifier = addElementsOfAClass(
+						elements, propertyHolder, isPropertyAnnotated,
+						accessType, clazz, mappings
+				);
+				hasIdentifier = hasIdentifier || currentHasIdentifier;
+			}
 		}
+		catch ( AnnotationException e ) {
+			exceptionWhileWalkingElements = e;
+		}
 
+		//TODO remember why it should be !inheritanceState.hasParents
 		if ( !hasIdentifier && !inheritanceState.hasParents ) {
-			if ( isExplicitPropertyAnnotated != null ) return null; //explicit but no @Id
+			if ( isExplicitPropertyAnnotated != null ) {
+				//the original exception is legitimate
+				if ( exceptionWhileWalkingElements != null) throw exceptionWhileWalkingElements;
+				return null; //explicit but no @Id: the upper layer will raise an exception
+			}
 			isPropertyAnnotated = !isPropertyAnnotated;
 			accessType = "field";
 			elements.clear();
@@ -873,6 +886,10 @@
 				hasIdentifier = hasIdentifier || currentHasIdentifier;
 			}
 		}
+
+		//the field show no id, fallback tot he original exception
+		if (!hasIdentifier && exceptionWhileWalkingElements != null) throw exceptionWhileWalkingElements;
+
 		//TODO set the access type here?
 		entityBinder.setPropertyAnnotated( isPropertyAnnotated );
 		entityBinder.setPropertyAccessor( accessType );
@@ -1004,7 +1021,7 @@
 
 		log.debug( "Processing " + propertyHolder.getEntityName() + " " + accessType + " annotation" );
 		List<XProperty> properties = annotatedClass.getDeclaredProperties( accessType );
-		//order so that property are used int he same order when binding native query
+		//order so that property are used in the same order when binding native query
 		Collections.sort( properties, new Comparator<XProperty>() {
 			public int compare(XProperty property1, XProperty property2) {
 				return property1.getName().compareTo( property2.getName() );

Added: annotations/trunk/src/test/org/hibernate/test/annotations/generics/Dummy.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/generics/Dummy.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/generics/Dummy.java	2008-03-04 03:37:29 UTC (rev 14385)
@@ -0,0 +1,36 @@
+//$
+package org.hibernate.test.annotations.generics;
+
+import javax.persistence.Transient;
+import javax.persistence.Id;
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+public class Dummy<K> {
+
+	@Id
+	private Long id;
+
+	@Transient
+	transient private K dummyField;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public K getDummyField() {
+		return dummyField;
+	}
+
+	public void setDummyField(K dummyField) {
+		this.dummyField = dummyField;
+	}
+
+} 
\ No newline at end of file

Modified: annotations/trunk/src/test/org/hibernate/test/annotations/generics/GenericsTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/generics/GenericsTest.java	2008-03-04 02:07:51 UTC (rev 14384)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/generics/GenericsTest.java	2008-03-04 03:37:29 UTC (rev 14385)
@@ -54,7 +54,10 @@
 				PaperType.class,
 				SomeGuy.class,
 				Price.class,
-				WildEntity.class
+				WildEntity.class,
+
+				//test at deployment only test unbound property when default field access is used
+				Dummy.class
 		};
 	}
 }

Deleted: annotations/trunk/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java	2008-03-04 02:07:51 UTC (rev 14384)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java	2008-03-04 03:37:29 UTC (rev 14385)
@@ -1,72 +0,0 @@
-//$Id: $
-package org.hibernate.test.annotations.idmanytoone;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.test.annotations.TestCase;
-
-/**
- * @author Emmanuel Bernard
- */
-public class IdManyToOne extends TestCase {
-	public void testFkCreationOrdering() throws Exception {
-		//no real test case, the sessionFactory building is tested
-		Session s = openSession();
-		s.close();
-	}
-
-	public void getBiDirOneToManyInId() throws Exception {
-		Session s = openSession();
-		Transaction tx = s.beginTransaction();
-		CardKey key = new CardKey();
-		s.persist( key );
-		Project project = new Project();
-		s.persist( project );
-		Card card = new Card();
-		card.getPrimaryKey().setProject( project );
-		s.persist( card );
-		CardField field = new CardField();
-		field.getPrimaryKey().setKey( key );
-		field.getPrimaryKey().setCard( card );
-		s.persist( field );
-		card.setMainCardField( field );
-		s.flush();
-		s.clear();
-		card = (Card) s.createQuery( "from Card c").list().get(0);
-		assertEquals( 1, card.getFields().size() );
-		assertEquals( card.getMainCardField(), card.getFields().iterator().next() );
-		tx.rollback();
-		s.close();
-	}
-
-	public void testIdClassManyToOne() {
-		Session s = openSession();
-		Transaction tx = s.beginTransaction();
-		Store store = new Store();
-		Customer customer = new Customer();
-		s.persist( store );
-		s.persist( customer );
-		StoreCustomer sc = new StoreCustomer( store, customer );
-		s.persist( sc );
-		s.flush();
-		s.clear();
-
-		store = (Store) s.get(Store.class, store.id );
-		assertEquals( 1, store.customers.size() );
-		assertEquals( customer.id, store.customers.iterator().next().customer.id );
-		tx.rollback();
-		s.close();
-	}
-
-	protected Class[] getMappings() {
-		return new Class[] {
-				Store.class,
-				Customer.class,
-				StoreCustomer.class,
-				CardKey.class,
-				CardField.class,
-				Card.class,
-				Project.class
-		};
-	}
-}




More information about the hibernate-commits mailing list