We're updating the issue view to help you get more done. 

ORM does not interpret Hibernate Validator constraints as DDL statements for @Embeddable attributes

Description

Hi

I am using Spring Boot 2 (2.0.1.RELEASE) with the default Hibernate version with H2 db and I have a problem with the field sizes in the table that is generated when using @Embeddable.

Here is my code:

@Entity
public class Publisher {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;

@NotBlank
@Size(min=2, max=150)
private String name;

@NotNull
private Address address;
...
}

@Embeddable
public class Address {

@NotBlank
@Size(min=3, max=100)
private String street;

@NotBlank
@Size(min=2, max=100)
private String city;

@NotBlank
@Size(min=2, max=100)
private String county;

@NotBlank
@Size(min=7, max=8)
private String postcode;
...
}

When Spring Boot fires up it creates the tables in H2. The column size in the 'name' attribute in Publisher is correctly set up to 150 using the max value from the @Size annotation.

The max values in the @Size annotations for the embedded Address entity is ignored and set to 255 chars max for all 4 fields.

Is this the expected behaviour or should the db columns from the embedded fields be set to the max value from the @Size annotations in the Address entity?

I know I can set this using the length value of the @Column annotation but I was hoping to get this working without the extra @Column annotation.

I originally raised this question on StackOverflow and was asked to submit this here:

https://stackoverflow.com/questions/50104083/spring-boot-2-hibernate-5-embeddable-attributes-generates-the-wrong-field-size/50104855#50104855

I haven't used Jira for a very long time so I apologise in advance if I make any mistakes in raising this issue.

Thank you
Kaz

Environment

I am using Spring Boot 2.0.1.RELEASE which pulls in Hibernate 5.2.16.Final with Hibernate Validator 6.0.9.Final

Status

Assignee

Unassigned

Reporter

Kaz

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.16

Priority

Major