[hibernate-commits] Hibernate SVN: r20767 - in core/trunk: testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/specjmapid and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Oct 4 05:45:10 EDT 2010


Author: epbernard
Date: 2010-10-04 05:45:09 -0400 (Mon, 04 Oct 2010)
New Revision: 20767

Modified:
   core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
   core/trunk/core/src/main/java/org/hibernate/cfg/BinderHelper.java
   core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
   core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/specjmapid/IdMapManyToOneSpecjTest.java
Log:
HHH-5578 Support SpecJ's proprietary syntax

Generalize the fix a bit
Clean some more style issues
Fix issues related to the atomicity test
  fixed setting proper value on property marked as many-to-one-key
  fixed parsing bug, now it shouldnt affect other many-to-one in the same entity
  fixed annotation check on many-to-one property

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java	2010-10-04 09:44:12 UTC (rev 20766)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java	2010-10-04 09:45:09 UTC (rev 20767)
@@ -1417,7 +1417,6 @@
 			 * TODO support true/false/default on the property instead of present / not present
 			 * TODO is @Column mandatory?
 			 * TODO add method support
-			 * TODO avoid custId hardcoded
 			 */
 			if ( System.getProperty( "hibernate.enable_specj_proprietary_syntax" ) != null ) {
 				if ( element.isAnnotationPresent( Id.class ) && element.isAnnotationPresent( Column.class ) ) {
@@ -1433,7 +1432,7 @@
 									propertyAccessor, //TODO we should get the right accessor but the same as id would do
 									mappings.getReflectionManager()
 							);
-							mappings.addPropertyAnnotatedWithMapsIdSpecj( entity, specJPropertyData, "custId" );
+							mappings.addPropertyAnnotatedWithMapsIdSpecj( entity, specJPropertyData, element.toString() );
 						}
 					}
 				}
@@ -2650,7 +2649,8 @@
 			}
 		}
 
-		//Make sure that JPA1 key-many-to-one columns are read only too
+		//Make sure that JPA1 key-many-to-one columns are read only tooj
+		boolean hasSpecjManyToOne=false;
 		if ( System.getProperty( "hibernate.enable_specj_proprietary_syntax" ) != null ) {
 			String columnName = "";
 			for ( XProperty prop : inferredData.getDeclaringClass()
@@ -2659,13 +2659,12 @@
 					columnName = prop.getAnnotation( Column.class ).name();
 				}
 
-				final JoinColumn joinColumn = prop.getAnnotation( JoinColumn.class );
-				if ( prop.isAnnotationPresent( ManyToOne.class ) && joinColumn != null
+				final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
+				if ( property.isAnnotationPresent( ManyToOne.class ) && joinColumn != null
 						&& !joinColumn.name().isEmpty()
 						&& joinColumn.name().equals( columnName )
-						&& !prop.isAnnotationPresent( MapsId.class ) )
-
-				{
+						&& !property.isAnnotationPresent( MapsId.class ) ) {
+				   hasSpecjManyToOne = true;
 					for ( Ejb3JoinColumn column : columns ) {
 						column.setInsertable( false );
 						column.setUpdatable( false );
@@ -2710,6 +2709,10 @@
 			propertyBinder.setInsertable( false );
 			propertyBinder.setUpdatable( false );
 		}
+		else if (hasSpecjManyToOne) {
+		   propertyBinder.setInsertable( false );
+           propertyBinder.setUpdatable( false );
+		}
 		else {
 			propertyBinder.setInsertable( columns[0].isInsertable() );
 			propertyBinder.setUpdatable( columns[0].isUpdatable() );

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/BinderHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/BinderHelper.java	2010-10-04 09:44:12 UTC (rev 20766)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/BinderHelper.java	2010-10-04 09:45:09 UTC (rev 20767)
@@ -681,7 +681,14 @@
 			throw new AssertionFailure( "PersistentClass name cannot be converted into a Class", e);
 		}
 		if ( propertyHolder.isInIdClass() ) {
-			return mappings.getPropertyAnnotatedWithIdAndToOne( persistentXClass, propertyName );
+			PropertyData pd = mappings.getPropertyAnnotatedWithIdAndToOne( persistentXClass, propertyName );
+			if ( pd == null ) {
+				String propertyPath = isId ? "" : propertyName;
+				return mappings.getPropertyAnnotatedWithMapsId( persistentXClass, propertyPath );
+			}
+			else {
+				return pd;
+			}
 		}
 		else {
 			String propertyPath = isId ? "" : propertyName;

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java	2010-10-04 09:44:12 UTC (rev 20766)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java	2010-10-04 09:45:09 UTC (rev 20767)
@@ -3594,15 +3594,15 @@
 			}
 			map.put( property.getProperty().getAnnotation( MapsId.class ).value(), property );
 		}
-		
+
 		public void addPropertyAnnotatedWithMapsIdSpecj(XClass entityType, PropertyData property, String mapsIdValue) {
-           Map<String, PropertyData> map = propertiesAnnotatedWithMapsId.get( entityType );
-           if ( map == null ) {
-               map = new HashMap<String, PropertyData>();
-               propertiesAnnotatedWithMapsId.put( entityType, map );
-           }
-           map.put( mapsIdValue, property );
-       }
+			Map<String, PropertyData> map = propertiesAnnotatedWithMapsId.get( entityType );
+			if ( map == null ) {
+				map = new HashMap<String, PropertyData>();
+				propertiesAnnotatedWithMapsId.put( entityType, map );
+			}
+			map.put( mapsIdValue, property );
+		}
 
 		public PropertyData getPropertyAnnotatedWithIdAndToOne(XClass entityType, String propertyName) {
 			final Map<String, PropertyData> map = propertiesAnnotatedWithIdAndToOne.get( entityType );

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/specjmapid/IdMapManyToOneSpecjTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/specjmapid/IdMapManyToOneSpecjTest.java	2010-10-04 09:44:12 UTC (rev 20766)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/specjmapid/IdMapManyToOneSpecjTest.java	2010-10-04 09:45:09 UTC (rev 20767)
@@ -43,6 +43,7 @@
 
 	public void testComplexIdClass() {
 
+
 		Session s = openSession();
 		Transaction tx = s.beginTransaction();
 
@@ -79,16 +80,17 @@
 
 		c1.addInventory( house, 100, new BigDecimal( 50000 ) );
 		s.merge( c1 );
-		s.flush();
-		s.clear();
+		tx.commit();
+		
 
+		tx = s.beginTransaction();
 		Customer c12 = ( Customer ) s.createQuery( "select c from Customer c" ).uniqueResult();
 
-//		c12.getBalance();
 		List<CustomerInventory> inventory = c12.getInventories();
 
 		assertEquals( 2, inventory.size() );
 		assertEquals( 10, inventory.get( 0 ).getQuantity() );
+		assertEquals( "2", inventory.get(1).getVehicle().getId());
 
 
 		Item house2 = new Item();
@@ -112,6 +114,20 @@
 				.uniqueResult();
 		assertEquals( 3, c13.getInventories().size() );
 
+		
+		
+		Customer customer2 = new Customer(
+                "foo2", "bar2", "contact12", "1002", new BigDecimal( 10002 ), new BigDecimal( 10002 ), new BigDecimal( 1000 ));
+		customer2.setId(2);
+		s.persist(customer2);
+		
+		customer2.addInventory(boat, 10, new BigDecimal(400));
+		customer2.addInventory(house2, 3, new BigDecimal(4000));
+		s.merge(customer2);
+		
+		Customer c23 = ( Customer ) s.createQuery( "select c from Customer c where c.id = 2" ).uniqueResult();
+		assertEquals( 2, c23.getInventories().size() );
+	
 		tx.rollback();
 		s.close();
 	}



More information about the hibernate-commits mailing list