0 Replies Latest reply on Mar 4, 2008 8:37 AM by mars1412

    @Length not working on embedded component

    mars1412 Apprentice

      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.

      • why is this different behavior?
      • what can I do about it?
      • or should I always use both annotations: @Length and @Column(lenght=xx)?


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


        length of email field in the table: 100 (as expected)
        length of city field in table: 255 (30 expected)