org.hibernate.hql.internal.ast.QuerySyntaxEx`概念:期待 OPEN,在第 1 列附近发现 'from'

org.hibernate.hql.internal.ast.QuerySyntaxEx`ception: expecting OPEN, found 'from' near line 1, column

我在 Spring Boot 1.5 中有一个项目,带有 mysql 数据库。我有 2 个实体 类 BackupOTP & OTP,我想使用 HQL 将数据从 OTP table 复制到 BackupOTP table .为此,我编写了这段代码。

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);

但我遇到以下异常:

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]

如何解决这个问题?

终于找到答案了

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.