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:
parent
768088881b
commit
6a14aeeba7
|
@ -496,7 +496,9 @@ public class Ejb3Column {
|
||||||
|
|
||||||
private void processExpression(ReadWriteExpression annotation) {
|
private void processExpression(ReadWriteExpression annotation) {
|
||||||
String nonNullLogicalColumnName = logicalColumnName != null ? logicalColumnName : ""; //use the default for annotations
|
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();
|
readExpression = annotation.read();
|
||||||
if ( StringHelper.isEmpty( readExpression ) ) {
|
if ( StringHelper.isEmpty( readExpression ) ) {
|
||||||
readExpression = null;
|
readExpression = null;
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.various.readwriteexpression;
|
package org.hibernate.test.annotations.various.readwriteexpression;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
@ -41,7 +39,7 @@ public class ReadWriteExpressionTest extends TestCase {
|
||||||
final double HEIGHT_INCHES = 73;
|
final double HEIGHT_INCHES = 73;
|
||||||
final double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
|
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.persist( staff );
|
||||||
s.flush();
|
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();
|
heightViaSql = (Double)s.createSQLQuery("select radiusS from t_staff where t_staff.id=1").uniqueResult();
|
||||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
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
|
// Test projection
|
||||||
Double heightViaHql = (Double)s.createQuery("select s.sizeInInches from Staff s where s.id = 1").uniqueResult();
|
Double heightViaHql = (Double)s.createQuery("select s.sizeInInches from Staff s where s.id = 1").uniqueResult();
|
||||||
assertEquals(HEIGHT_INCHES, heightViaHql, 0.01d);
|
assertEquals(HEIGHT_INCHES, heightViaHql, 0.01d);
|
||||||
|
|
|
@ -37,9 +37,10 @@ import org.hibernate.annotations.ReadWriteExpression;
|
||||||
@Table(name="t_staff")
|
@Table(name="t_staff")
|
||||||
public class 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.sizeInInches = sizeInInches;
|
||||||
this.radiusS = radius;
|
this.radiusS = radius;
|
||||||
|
this.diameter = diameter;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,10 +58,19 @@ public class Staff {
|
||||||
public void setSizeInInches(double sizeInInches) { this.sizeInInches = sizeInInches; }
|
public void setSizeInInches(double sizeInInches) { this.sizeInInches = sizeInInches; }
|
||||||
private double sizeInInches;
|
private double sizeInInches;
|
||||||
|
|
||||||
|
//Weird extra S to avoid potential SQL keywords
|
||||||
@ReadWriteExpression(
|
@ReadWriteExpression(
|
||||||
read = "radiusS / 2.54",
|
read = "radiusS / 2.54",
|
||||||
write = "? * 2.54" )
|
write = "? * 2.54" )
|
||||||
public double getRadiusS() { return radiusS; }
|
public double getRadiusS() { return radiusS; }
|
||||||
public void setRadiusS(double radiusS) { this.radiusS = radiusS; }
|
public void setRadiusS(double radiusS) { this.radiusS = radiusS; }
|
||||||
private double 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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue