Hibernate version: 3.2.3.GA
I think that there's a bug in PersistentClass.
I have the following mapped class:
Code:
@Entity
@Table(name = "OPER_INCOMINGFLIGHTS")
public class IncomingFlight {
private Long oid;
private IATAFlightNumber iataFlightNumber;
private String flightNumber;
...
@Embedded
@AttributeOverrides( ... )
public IATAFlightNumber getIataFlightNumber() {
return iataFlightNumber;
}
...
@Column(length = 12)
public String getFlightNumber() {
return flightNumber;
}
}
This class embeds a component:
Code:
@Embeddable
public class IATAFlightNumber {
private String airlineCode;
private String flightNumber;
private String suffix;
...
@Column(length = 8)
public String getFlightNumber() {
return flightNumber;
}
...
}
PersistentClass checks the mapped classes for duplicate properties. Unfortunately it treats properties that are included inside embedded Components just like if they were part of the (surrounding) mapped class. In my special case a...
Code:
org.hibernate.MappingException: Repeated column in mapping for entity: at.vie.mach2.flight.flightops.flight.IncomingFlight column: flightNumber (should be mapped with insert="false" update="false")
...exception is thrown.
The reason for this is (from org.hibernate.mapping.PersistentClass):
Code:
protected void checkPropertyColumnDuplication(Set distinctColumns, Iterator properties)
throws MappingException {
while ( properties.hasNext() ) {
Property prop = (Property) properties.next();
if ( prop.getValue() instanceof Component ) { //TODO: remove use of instanceof!
Component component = (Component) prop.getValue();
checkPropertyColumnDuplication( distinctColumns, component.getPropertyIterator() );
}
else {
if ( prop.isUpdateable() || prop.isInsertable() ) {
checkColumnDuplication( distinctColumns, prop.getColumnIterator() );
}
}
}
}
As you can see the collection distinctColumns is used both for first level properties and component properties, although the component properties are in a different class.
As a result the namespaces are mixed up.
Is this a bug or am I missing something ?