diff --git a/src/java/com/samskivert/depot/impl/BuildVisitor.java b/src/java/com/samskivert/depot/impl/BuildVisitor.java index ed51fad..56879a5 100644 --- a/src/java/com/samskivert/depot/impl/BuildVisitor.java +++ b/src/java/com/samskivert/depot/impl/BuildVisitor.java @@ -132,10 +132,6 @@ public abstract class BuildVisitor implements FragmentVisitor public Void visit (FieldDefinition definition) { definition.getDefinition().accept(this); - if (_enableAliasing) { - _builder.append(" as "); - appendIdentifier(definition.getField()); - } return null; } @@ -816,6 +812,10 @@ public abstract class BuildVisitor implements FragmentVisitor boolean saved = _enableOverrides; _enableOverrides = false; fieldDef.accept(this); + if (_enableAliasing) { + _builder.append(" as "); + appendIdentifier(fm.getColumnName()); + } _enableOverrides = saved; return; } @@ -844,7 +844,7 @@ public abstract class BuildVisitor implements FragmentVisitor _builder.append(fieldComputed.fieldDefinition()); if (_enableAliasing) { _builder.append(" as "); - appendIdentifier(field.name); + appendIdentifier(fm.getColumnName()); } return; } diff --git a/src/java/com/samskivert/depot/impl/FieldMarshaller.java b/src/java/com/samskivert/depot/impl/FieldMarshaller.java index c74d40a..ce0be21 100644 --- a/src/java/com/samskivert/depot/impl/FieldMarshaller.java +++ b/src/java/com/samskivert/depot/impl/FieldMarshaller.java @@ -34,6 +34,7 @@ import java.sql.Time; import java.sql.Timestamp; import com.samskivert.depot.DatabaseException; +import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.Transformer; import com.samskivert.depot.annotation.Column; import com.samskivert.depot.annotation.Computed; @@ -216,15 +217,30 @@ public abstract class FieldMarshaller { _field = field; _columnName = field.getName(); + _computed = field.getAnnotation(Computed.class); Column column = _field.getAnnotation(Column.class); + if (column == null) { + // look for a column annotation on the shadowed field, if any + Computed dcomputed = (_computed == null) ? + field.getDeclaringClass().getAnnotation(Computed.class) : _computed; + if (dcomputed != null) { + Class sclass = dcomputed.shadowOf(); + if (sclass != null) { + try { + column = sclass.getField(field.getName()).getAnnotation(Column.class); + } catch (NoSuchFieldException e) { + // no problem; assume that it will be defined in the query + } + } + } + } if (column != null) { if (!StringUtil.isBlank(column.name())) { _columnName = column.name(); } } - _computed = field.getAnnotation(Computed.class); if (_computed != null) { return; }