views:

473

answers:

0

Hi all,

Fairly specific question here, but it's been bugging me for a day now:
I'm using Hibernate Core, Annotations & Validator on PostgreSQL 8.3.

I have the following classes setup:

@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;
...

I'd like to see the Length constraint translated to a length contraint in my PostgreSQL database (which is working for other fields inside @Entity's rather than @Embeddable's) but it just doesnt seem to want to work..
Even using an @IdClass instead of @EmbeddedId and applying the Length constraint on the matching field in the @Entity did not fix this problem: the database field is still varchar 255 (about 250 too large for my needs).
Some might say I shouldn't care about this level of detail, but my OCD side is refusing to let it go.. ;) Is it just not possible to use Hibernate Validator Annotations inside an EmbeddedId and have hbm2ddl apply the constraints to the database fields?