gpt4 book ai didi

java - JPA更新查询问题

转载 作者:行者123 更新时间:2023-11-30 03:51:09 25 4
gpt4 key购买 nike

假设我们有 2 个实体

@Entity(name = "user")
@Inheritance(strategy = InheritanceType.JOINED)
public class User{

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

private String name;
}

另一个继承类

@Entity
public class ExtendedUser extends User{
private String bio;
}

现在当我尝试运行 JPA 更新查询时

@Modifying
@Query("update ExtendedUser set bio=?2 where id=?1")
void updateOverflowText(Long id,String bio);

由于列“id”不明确,我遇到异常,无法运行查询

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'id' in where clause is ambiguous
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2450)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2371)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2355)
at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:142)
... 103 more

最佳答案

试试这个

update User usr set usr.bio=?2 where usr.id=?1

关于java - JPA更新查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24423163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com