views:

10

answers:

0

When using the @Any annotation in hibernate how can you create the reverse mapping field, for use with orphan removal. My code looks like the example below, except that classes A and B each have their own inheritance hierarchies which is why I can not make Interface I an abstract class.

public Interface I;

@Entity
public Class A implements I {

}

@Entity
public Class B implements I {

}

@Entity Class C {

    @Any(metaDef = "iTypename", metaColumn = @Column(name = "i_type"))
    @JoinColumn(name = "i_id")
    private I iInstance;
}

Located as package annotation
@AnyMetaDef(
    name = "iTypename",
    idType = "long",
    metaType = "string",
    metaValues = {
        @MetaValue(value = "aTypename", targetEntity = A.class),
        @MetaValue(value = "bTypename", targetEntity = B.class)
    }
)

In both Class A and Class B I tried to add
@OneToMany (fetch = FetchType.LAZY, orphanRemoval = true, mappedBy = "iInstance")
private Set<C> cInstances;

Only when starting my application I got the following Exception:
org.hibernate.MappingException: Foreign key (FK127E590D9C408:C [i_type,i_id])) must have same number of columns as the referenced primary key (A [id])

Is there a way to map the reverse of the @Any relation from the other side?

Thanks in advance,
Mark