Issue
I have a project in Spring Boot 1.5 with mysql
database. I have 2 entity classes BackupOTP
& OTP
and I want to copy data from OTP
table to BackupOTP
table using HQL. For that I have written this code.
Query query=session.createQuery("insert into BackupOTP from OTP where isExpired=:boolean");
query.setBoolean("boolean", true);
int i=query.executeUpdate();
System.err.println("i = "+i);
But I am experiecning the below exception:
org.hibernate.hql.internal.ast.QuerySyntaxException:
expecting OPEN, found 'from' near line 1, column 23
[insert into BackupOTP from com.altafjava.central.entity.OTP where isExpired=:boolean]
How to resolve this issue?
Solution
Finally, I got the answer.
Actually, It was the problem with HQL syntax. My HQL syntax was wrong. I looked into Hibernate insert query documentation and modified my insert syntax like this
Query query=session.createQuery("insert into BackupOTP (otpId, createdTime, encryptedOTP, isExpired, updatedTime)"
+ " select otpId, createdTime, encryptedOTP, isExpired, updatedTime from OTP where isExpired=:boolean");
query.setBoolean("boolean", true);
int i=query.executeUpdate();
System.err.println("i = "+i);
Now it is working.
Answered By - Altaf Ansari