I use spring-jpa with hibernate implementation. I use mariadb I try to do an update with a join.
My object structure
@Entity
public class Room {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long roomId;
@ManyToOne
@JoinColumn(name = "appartment_id")
private Appartment appartment;
}
@Entity
public class Appartment {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long appartmentId;
@OneToMany
@JoinColumn(name="appartment_id")
private Set<Room> roomList;
}
My sql query
update Room r1 set r1.available = :availability
where r1.roomId in (
SELECT r2.roomId
from Room r2
JOIN r2.appartment a1
WHERE a1.appartmentId = :appartmentId
tried also
update Room r1 set r1.available = :availability
where exists
( SELECT r2
from Room r2
JOIN r2.appartment a1
where a1.appartmentId= :appartmentId
)
I get this error
java.sql.SQLException: Table 'room' is specified twice, both as a target for 'UPDATE' and as a separate source for data
Seem like update and join with mysql seem impossible?