HHH-4510 Allow forColumn to be left if a property has a single column

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20746 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-09-29 09:12:51 +00:00
parent 558d9469e0
commit 768088881b
4 changed files with 25 additions and 9 deletions

View File

@ -44,7 +44,7 @@ public @interface ReadWriteExpression {
/**
* (Logical) column name for which the expression is used
*/
String forColumn();
String forColumn() default "";
/**
* Custom SQL expression used to read from the column

View File

@ -495,7 +495,8 @@ public class Ejb3Column {
}
private void processExpression(ReadWriteExpression annotation) {
if ( annotation != null && annotation.forColumn().equals( logicalColumnName ) ) {
String nonNullLogicalColumnName = logicalColumnName != null ? logicalColumnName : ""; //use the default for annotations
if ( annotation != null && annotation.forColumn().equals( nonNullLogicalColumnName ) ) {
readExpression = annotation.read();
if ( StringHelper.isEmpty( readExpression ) ) {
readExpression = null;

View File

@ -5794,7 +5794,6 @@ class LineItem {
class CreditCard {
@Column(name="credit_card_num")
@ReadWriteExpression(
forColumn="credit_card_num",
read="decrypt(credit_card_num)",
write="encrypt(?)")
public String getCreditCardNumber() { return creditCardNumber; }
@ -5812,12 +5811,30 @@ class CreditCard {
&lt;/property&gt;</programlisting>
<note>
<para>When using <classname>@ReadWriteExpression</classname>, you must
explicitly declare the <literal>@Column.name</literal> property. You can
use the plural form <classname>@ReadWriteExpressions</classname> if more
than one columns need to define either of these rules.</para>
<para>You can use the plural form
<classname>@ReadWriteExpressions</classname> if more than one columns
need to define either of these rules.</para>
</note>
<para>If a property uses more that one column, you must use the
<literal>forColumn</literal> attribute to specify which column, the
expressions are targeting.</para>
<programlisting role="JAVA">@Entity
class User {
@Type(type="com.acme.type.CreditCardType")
@Columns( {
@Column(name="credit_card_num"),
@Column(name="exp_date") } )
@ReadWriteExpression(
forColumn="credit_card_num",
read="decrypt(credit_card_num)",
write="encrypt(?)")
public CreditCard getCreditCard() { return creditCard; }
public void setCreditCard(CreditCard card) { this.creditCard = card; }
private CreditCard creditCard;
}</programlisting>
<para>Hibernate applies the custom expressions automatically whenever the
property is referenced in a query. This functionality is similar to a
derived-property <literal>formula</literal> with two differences:

View File

@ -57,9 +57,7 @@ public class Staff {
public void setSizeInInches(double sizeInInches) { this.sizeInInches = sizeInInches; }
private double sizeInInches;
@Column(name="radiusS")
@ReadWriteExpression(
forColumn = "radiusS",
read = "radiusS / 2.54",
write = "? * 2.54" )
public double getRadiusS() { return radiusS; }