-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Validator annotations not creating DDL for components
PostPosted: Fri Jun 01, 2007 11:18 pm 
Newbie

Joined: Fri Jun 01, 2007 10:41 pm
Posts: 4
Location: Australia
Hello, I am attempting to use Hibernate Validator on my project (3.0.0ga with Hibernate 3.2.1).

I have several entities that contain components (i.e. a POJO with the @Embeddable annotation). I also have domain objects that inherit from a superclass POJO that contains auditing fields e.g. last updated time, last updated user etc.

The problem I am experiencing is that the DDL generated by Hibernate Validator is ignoring the validator annotations on the components and superclass fields e.g.

Code:
@Entity(table = "myTable")
public class MyEntity {
...
    @Embedded
    @Valid
    public Address getAddress() {
        return address;
    }

    @Column(name = "myColumn")
    @Length(max = 10)
    @NotNull
    public String getMyColumn () {
        return myColumn;
    }
}

@Embeddable
public class Address {
...
    @Column(name = "city")
    @Length(max = 20)
    @NotNull
    public String getCity() {
        return city;
    }
}


When hbm2ddl runs it generates something similar to the following DDL

Code:
create myTable (
    city varchar(255) null,      <-- should be varchar(20) not null
    myColumn varchar(10) not null
)


i.e. Hibernate Validator has correctly applied the Validator annotations to the fields in MyEntity but it has ignored the validator annotations on the embedded Address component.

I have a similar issue with inherited properties i.e. the validator annotations on those properties are ignored in the generated DDL. The actual validation of the components and inherited properties *is* working - its just that the generated database schema is wrong.

Is this just a limitation of Hibernate Validator or is it supposed to be able to generate the correct DDL for components and inherited properties (i.e. have I configured something wrong)?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 03, 2007 10:33 pm 
Newbie

Joined: Fri Jun 01, 2007 10:41 pm
Posts: 4
Location: Australia
Looks like this might be a bug - see http://opensource.atlassian.com/projects/hibernate/browse/HV-16.

This is rather poor, given that any substantial hibernate project is going to have components in it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 12:45 am 
Newbie

Joined: Fri Jun 01, 2007 10:41 pm
Posts: 4
Location: Australia
To eliminate the possibility of a configuration error on my part, I downloaded the Validator example code from the article at http://www.ibm.com/developerworks/web/l ... ibval.html

When I generated the database schema for this example the same issues were present i.e. component and superclass validations were not applied to the generated DDL.

I've raised a bug for this (http://opensource.atlassian.com/projects/hibernate/browse/HV-25) as I now have to define my field lengths twice, once to get Validator to work properly and again to get the correct database schema generated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 6:47 pm 
Newbie

Joined: Fri Jun 01, 2007 10:41 pm
Posts: 4
Location: Australia
So this is what I currently have to do use Validator and have my database schema generated correctly:

@Column(name = "EMAIL_ADDRESS", length = EMAIL_ADDRESS_MAX_LENGTH, nullable = false)
@NotNull
@Length(max = EMAIL_ADDRESS_MAX_LENGTH)
@Email
public String getEmailAddress() {
return emailAddress;
}

I have to specify the column lengths in two places but at least a static property can be used to ensure the actual length is maintained in one place. However it looks like the not-null status just has to be declared twice.

Anyone have any better ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 9:03 pm 
Newbie

Joined: Fri Oct 05, 2007 8:50 am
Posts: 2
I have encountered this problem as well. No DDL appears to be generated for embedded components. I've added a comment to
http://opensource.atlassian.com/projects/hibernate/browse/HV-25
pointing at a place in the code that could be the problem.

I'd really like this to be fixed as soon as possible, as the workarounds are quite painful.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.