HHH-4510 Fix bug where explicit @Column would not match @ReadWriteExpresion with empty forColumn

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20747 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-09-29 09:42:52 +00:00
parent 768088881b
commit 6a14aeeba7
3 changed files with 18 additions and 5 deletions

View File

@ -496,7 +496,9 @@ public class Ejb3Column {
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;

View File

@ -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 @@ public class ReadWriteExpressionTest extends TestCase {
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 @@ public class ReadWriteExpressionTest extends TestCase {
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);

View File

@ -37,9 +37,10 @@ import org.hibernate.annotations.ReadWriteExpression;
@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 class Staff {
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;
}