[hibernate-commits] Hibernate SVN: r20747 - in core/trunk: testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Sep 29 05:42:52 EDT 2010


Author: epbernard
Date: 2010-09-29 05:42:52 -0400 (Wed, 29 Sep 2010)
New Revision: 20747

Modified:
   core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java
   core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/ReadWriteExpressionTest.java
   core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java
Log:
HHH-4510 Fix bug where explicit @Column would not match @ReadWriteExpresion with empty forColumn

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java	2010-09-29 09:12:51 UTC (rev 20746)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java	2010-09-29 09:42:52 UTC (rev 20747)
@@ -496,7 +496,9 @@
 
 	private void processExpression(ReadWriteExpression annotation) {
 		String nonNullLogicalColumnName = logicalColumnName != null ? logicalColumnName : ""; //use the default for annotations 
-		if ( annotation != null && annotation.forColumn().equals( nonNullLogicalColumnName ) ) {
+		if ( annotation != null &&
+				( StringHelper.isEmpty( annotation.forColumn() )
+						|| annotation.forColumn().equals( nonNullLogicalColumnName ) ) ) {
 			readExpression = annotation.read();
 			if ( StringHelper.isEmpty( readExpression ) ) {
 				readExpression = null;

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/ReadWriteExpressionTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/ReadWriteExpressionTest.java	2010-09-29 09:12:51 UTC (rev 20746)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/ReadWriteExpressionTest.java	2010-09-29 09:42:52 UTC (rev 20747)
@@ -23,8 +23,6 @@
  */
 package org.hibernate.test.annotations.various.readwriteexpression;
 
-import java.util.Date;
-
 import org.hibernate.Session;
 import org.hibernate.Transaction;
 import org.hibernate.criterion.Restrictions;
@@ -41,7 +39,7 @@
 		final double HEIGHT_INCHES = 73;
 		final double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
 
-		Staff staff = new Staff(HEIGHT_INCHES, HEIGHT_INCHES, 1);
+		Staff staff = new Staff(HEIGHT_INCHES, HEIGHT_INCHES, HEIGHT_INCHES*2, 1);
 		s.persist( staff );
 		s.flush();
 
@@ -52,6 +50,9 @@
 		heightViaSql = (Double)s.createSQLQuery("select radiusS from t_staff where t_staff.id=1").uniqueResult();
 		assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
 
+		heightViaSql = (Double)s.createSQLQuery("select diamet from t_staff where t_staff.id=1").uniqueResult();
+		assertEquals(HEIGHT_CENTIMETERS*2, heightViaSql, 0.01d);
+
 		// Test projection
 		Double heightViaHql = (Double)s.createQuery("select s.sizeInInches from Staff s where s.id = 1").uniqueResult();
 		assertEquals(HEIGHT_INCHES, heightViaHql, 0.01d);

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java	2010-09-29 09:12:51 UTC (rev 20746)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java	2010-09-29 09:42:52 UTC (rev 20747)
@@ -37,9 +37,10 @@
 @Table(name="t_staff")
 public class Staff {
 
-	public Staff(double sizeInInches, double radius, Integer id) {
+	public Staff(double sizeInInches, double radius, double diameter, Integer id) {
 		this.sizeInInches = sizeInInches;
 		this.radiusS = radius;
+		this.diameter = diameter;
 		this.id = id;
 	}
 
@@ -57,10 +58,19 @@
 	public void setSizeInInches(double sizeInInches) {  this.sizeInInches = sizeInInches; }
 	private double sizeInInches;
 
+	//Weird extra S to avoid potential SQL keywords
 	@ReadWriteExpression(
 			read = "radiusS / 2.54",
 			write = "? * 2.54" )
 	public double getRadiusS() { return radiusS; }
 	public void setRadiusS(double radiusS) {  this.radiusS = radiusS; }
 	private double radiusS;
+
+	@Column(name="diamet")
+	@ReadWriteExpression(
+			read = "diamet / 2.54",
+			write = "? * 2.54" )
+	public double getDiameter() { return diameter; }
+	public void setDiameter(double diameter) {  this.diameter = diameter; }
+	private double diameter;
 }



More information about the hibernate-commits mailing list