簡単なJPAの質問であることを願っています。次のクラス構造があるとします。
@Entity
@Table(name="foo_table")
class Foo{
@Id @Column(name="ID")
String id;
...
@ManyToOne()
@JoinColumn(name="BAR_ID")
Bar bar;
}
@Entity
@Table(name="bar_table")
class Bar{
@Id @Column(name="ID")
String id;
@Column(name="COL3")
String col3;
}
シナリオ: "Foo" レコードが関連付けられている "Bar" を更新したいとします。
これまでに使用したクエリは次のとおりです。
EntityTransaction tx = em.getTransaction();
tx.begin();
int rowsUpdated = em.createQuery("UPDATE Foo f SET bar = :bar " +
"WHERE f.id = :fooId").
setParameter("fooId", fooId).
setParameter("bar", newBar).
executeUpdate();
tx.commit();
質問: foo_table のみを更新し、bar_table を更新しない JPA 更新で行うことは可能ですか。DBA は bar_table の更新権限を私に与えたくありませんが、JPA は「深い」更新を行い、foo_table と bar_table の両方を更新したいと考えているようです。ありがとう!