这里有一个相当具体的问题,但它已经困扰了我一天了:
我在 PostgreSQL 8.3 上使用 Hibernate Core、Annotations & Validator。
我有以下课程设置:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Entry {
@EmbeddedId
protected EntryPK entryPK;
@ManyToMany
private Set<Comment> comments = new HashSet<Comment>();
...
@Embeddable
public class EntryPK implements Serializable {
@ManyToOne(cascade = CascadeType.ALL)
private Database database;
@Length(max = 50)
@NotEmpty
private String pdbid;
...
我希望在我的 PostgreSQL 数据库中看到长度约束转换为长度约束(它适用于@Entity而不是@Embeddable's中的其他字段)但它似乎不想工作..
即使使用@IdClass代替@EmbeddedId 并在 @Entity 中的匹配字段上应用长度约束并没有解决这个问题:数据库字段仍然是 varchar 255(对于我的需要来说,大约 250 太大了)。
有人可能会说我不应该关心这个级别的细节,但是我的强迫症方面拒绝放手.. ;) 是否不可能在 EmbeddedId 中使用 Hibernate Validator Annotations 并让 hbm2ddl 将约束应用于数据库领域?