Skip to content
Advertisement

Insert with Hibernate native query does not work for java.util.Date

I am using Hibernate JPA and Spring with a Mysql database and I want to insert using a SQL statement like this:

But after running it I get the following error:

Could someone help me on this please?

PS. I am aware of using hibernate in non-native way, but I need to use native way. I am also of insert …from… , but I don’t think it will help.

Finally I think the problem is mainly with the date. How do you guys pass on MySQL a datetime type using Java?

Update:

The following works fine, I guess it is a java date to mysql datetime conversion problem.

Could anyone please help me on how to convert java.util.Date to MySQL datetime?

Advertisement

Answer

Don’t use concatenation to insert data into queries, use parameters instead. It solves problem with wrong representation of values, as well as many other problems:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement