Filippo1980
Filippo1980

Reputation: 2735

How use java.time.LocalDate using Hibernate5 and Vaadin8?

I'm new on Vaadin and I'm trying to do a simple crud application. I was starting from Vaadin CRUD sample; then I modify the backend project to use Hibernate and the ui project to manage the various tables. I can do that for simple data type like varchar and int, now I would add a date's field but it returns me this error:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '\xAC\xED\x00\x05sr\x00\x0Djava.time.Ser\x95]\x84\xBA\x1B"H\xB2\x0C\x00\x00xpw\x07\x03\x00\x00\x07\xE1\x06\x1Ax' for column 'data_nascita' at row 1

"DATA_NASCITA" is a date column on my mysql DB and the entity has a LocalDate linked to this field.

I found somewhere that this new java api is compatible only with Hibernate5 so in my pom file I add:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.10.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
    <version>5.1.0.Final</version>
</dependency>

and into the entity class I replace java.util.Date with java.time.LocalDate and delete the annotation @temporal. The input class for this field is a DateField of Vaadin framework.

Which could be the problem?

P.S.: I'm blind, so I'm compiling the code with Netbeans8 but I modify the code with notepad++ so, if someone use the same technologies and hasn't any problem please tell me because I can't be sure that the problem is something with build process.

Upvotes: 1

Views: 520

Answers (1)

holi-java
holi-java

Reputation: 30676

IF your hibernate version is greater than 5.2.+ you can just using column as below:

@Column
private LocalDate date;

Otherwise you need install hibernate-java8 module into your project.

On the other hand, you shouldn't install hibernate-java8 module into your project if the hibernate version >= 5.2, maybe it will makes some conflict, since the hibernate-java8 module is merged into hibernate.

Upvotes: 2

Related Questions