埋め込みエンティティを更新しようとしていますが、JPAが間違ったSQLを生成しているようです。
ロゴエンティティが埋め込まれた会社エンティティがあります
@Entity
public class Company {
private Long id;
@Embedded
private Logo logo;
// Omitted other fields, getters, setters, etc
}
@Embeddable
public class Logo {
private String fileName;
private String fileExtension;
private String imageDataType;
// Omitted getters and setters
}
私のDAOメソッドでは、次のように埋め込まれたロゴを更新しようとしています。
@Override
public void setLogo(Logo logo, Long companyId) {
String q = "update Company c SET c.logo = :logo where c.id = :companyId";
Query query = entityManager.createQuery(q);
query.setParameter("companyId", companyId);
query.setParameter("logo", logo);
query.executeUpdate();
}
JPA(実際にはHibernate)は次のSQLを生成します。
update px_company set file_extension, file_name, file_type=(?, ?, ?) where id=?
Hibernateは、3つの埋め込みロゴフィールドを更新する必要があることを理解しているようですが、無効なSQLを生成します。生成されたSQLはエラーになります。
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' file_name, file_type=('jpg', '7679075394', 0) where id=1' at line 1
埋め込まれたエンティティを更新する方法はありますか?