Java JPA更新查询问题
假设我们有两个实体Java JPA更新查询问题,java,jpa,Java,Jpa,假设我们有两个实体 @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 Us
@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”列不明确
试试这个
更新用户usr set usr.bio=?2,其中usr.id=?1
试试这个:
@Modifying
@Query( nativeQuery = true, value = "update user set bio=?2 where id=?1")
int updateOverflowText( Long id, String bio ); `
尝试更新ExtendeDeduser usr set usr.bio=?2,其中usr.id=?1。但是它不起作用,如果你在后端用值执行相同的update语句以查看它是否正常工作,这可能会对你有所帮助。我不知道,以“try”开头的答案让我觉得作者不确定提议的更改将产生什么样的效果。无论如何,如果你能解释为什么你的解决方案能解决问题,我会更有信心。-话虽如此,欢迎来到stack overflow,并感谢分享您的知识:)介意一点吗?
@Modifying
@Query( nativeQuery = true, value = "update user set bio=?2 where id=?1")
int updateOverflowText( Long id, String bio ); `