I have an entity with a collection of embedded components. In JPA, this is indicated with @ElementCollection. This causes two problems. First, the default column names generated for the embedded component (e.g. DDL generation) are syntactically invalid (and do not follow the spec). Second, none of the meta information for the for the embedded component columns are used (e.g. column length, not null, etc).
Here is my code:
Code:
@Entity
public class ATest1 {
@Id
private long id;
@ElementCollection @OrderColumn
List<ATest2> twos = new ArrayList<ATest2>();
}
Code:
@Embeddable
public class ATest2 {
private String name;
}
When I export the DDL, I get the following:
Quote:
Unsuccessful: create table ATest1_twos (ATest1_id bigint not null, twos_collection&&element_name varchar(255), twos_ORDER integer not null, primary key (ATest1_id, twos_ORDER)) ENGINE=InnoDB
As you can see, Hibernate generates the woefully wrong column name "twos_collection&&element_name" and it is unaware of the NotNull and Size annotations (which work everywhere else).
This affects Hibernate 3.5.2, 3.5.3, and all 3.6.0 betas.
If it means anything, I am using DefaultComponentSafeNamingStrategy. I have tried creating my own naming strategy, but Hibernate ignores it when generating the column names for component collections.
It is worth noting that if I use @Column to specify nullable=false and length=10, those are carried through to the DDL. And if I use @Column to specify an explicit name, that name is used as well. Unfortunately, I plan to embed this component multiple times, so hard-coding column names using @Column won't work for me.
Please tell me I am missing something obvious.
Thank you,
Ted