When I use @Length annotation on the fields of my entity, the column in the table is created with the expected length (see email field in the example below)
But in embedded components, it seems that the @Length annotation is ignored (when creating the table) and the column in the table is always 255 characters long.
If I also add the @Column(lenght=xx) annotation on the embedded string, it works as expected.
@Entity
@Table(appliesTo = "WEBUSER", indexes = { @Index(name = "IDX_WEBUSER_NAME_FIRSTNAME", columnNames = { "NAME", "FIRSTNAME" }) })
@NamedQuery(name = "WebUser.getByEmail", query = "select u from WebUser u where u.email = :email")
public class WebUser implements Serializable {
private Long id;
private String email;
private Address address = new Address();
...
@Id @GeneratedValue
public Long getId() {
return id;
}
@Length(max=100)
@NotEmpty
@Email
public String getEmail() {
return email;
}
@Valid
@Embedded
public Address getAddress() {
return address;
}
...
}@Embeddable
public class Address implements Serializable {
private String city;
@Length(max=30)
@NotEmpty
public String getCity() {
return city;
}
...