(This behavior is exhibited in 3.5.6-Final, 3.6.5.Final, and 3.6.7.Final).
I'm pretty sure this is a bug, but I'm posting here first in case I've missed something. I'm using Hibernate as a JPA 2 provider with Spring 3.0.5. The idea below is that Parent contains a collection of @Embeddable objects of type A. Class A then further contains another single @Embeddable of type B. The annotations on Parent and A work just fine; the JPA annotations on B are completely ignored (see comments inline on B, below.)
Code:
@Entity
@Table(name="parent")
public class Parent {
@Id @GeneratedValue Long id;
...
@ElementCollection(fetch=FetchType.LAZY, targetClass=A.class)
@CollectionTable(name="a", joinColumns={@JoinColumn(name="parent_id", nullable=false)}
@ForeignKey(name="a_parent_id_fkey")
private Collection<A> aObjs = new ArrayList<A>();
...
}
@Embeddable
public class A {
@Column(name="a_string", nullable=false)
private String aString = "";
@Embedded
private B b = new B();
...
}
@Embeddable
public class B {
// This line is ignored: Hibernate's ORM modeling expects this database column to be named "bString",
// even though the @Column annotation tells it to be "b_string"
@Column(name="b_string", nullable=false)
private String bString;
...
}
The example above can sometimes be (poorly) worked around with @AttributeOverride,
as long basic types are used with defaults. However, if I add this to B:
Code:
@Column(name="enum_value", nullable=false)
@Enumerated(EnumType.STRING)
private SomeEnum myEnum;
the workaround does not work: the default for enums is to use their ordinal values in the column, and not their string representations - so in this case, I'll have "enum_value VARCHAR(255) NOT NULL" in my database schema, but the Hibernate mapping will expect an integer type for the ordinal value.
The presence or absence of @Embedded on the "B" type in class A does not affect the outcome.
Finally, I know the annotations on class B work - for example, if I have @Entity Parent -> @OneToMany SomeClass -> @Embedded B as my object hierarchy, Hibernate maps the columns using the annotations on B correctly.
Am I missing something, or is this a bug in Hibernate? (JPA 2 defines nested @Embeddables, so I don't see why this shouldn't work.)