| Hello, I have the following entity:
@Entity
public class Product {
@ElementCollection(targetClass = LocalizedValue.class)
@CollectionTable(name = "product_name_lv"), joinColumns = {
@JoinColumn(name = "product_pk"))
}, indexes = {
@Index(columnList = "product_pk"))
})
@MapKeyColumn(name = "locale")
private Map<Locale, LocalizedValueInterface> name;
......
}
So basically a product with a name where the name is a Map of Locale - LocalizedValueInterface and this interface is the interface for the LocalizedValue embeddable class:
@Access(AccessType.FIELD)
@Embeddable
public class LocalizedValue
implements LocalizedValueInterface
{
@Column(name = "val")
private String value;
}
Now when Hibernate creates the JPA Metamodel I see what ends in there is a collection of all entities (which correctly contains my Product entity) and a collection of all embeddables (which incorrectly contains only the LocalizedValueInterface). I followed the code and found out this:
ParameterizedType signatureType = getSignatureType( member );
if ( keyPersistentAttributeType == null ) {
elementJavaType = signatureType != null ?
getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
Object.class; keyJavaType = null;
}
else {
keyJavaType = signatureType != null ?
getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
Object.class; elementJavaType = signatureType != null ?
getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] ) :
Object.class; }
in AttributeFactory#PluralAttributeMetadataImpl on line 781. This code inspects the map and takes the second class in the generics argument and uses it for embeddable class. I think it should take it from the @ElementCollection(targetClass = LocalizedValue.class) annotation, or it should scan the classpath for @Embeddable annotation and all those that have it. |