The EntityManager.lock() seems to use the wrong column name when it is passed a sub-type entity froma joined inheritance strategy.
ie, I would expect to see:
update SUPER set ROW_VERSION_SEQ=? where SUPER_ID=? and ROW_VERSION_SEQ=?
but instead I see:
update SUPER set ROW_VERSION_SEQ=? where SUB_ID=? and ROW_VERSION_SEQ=?
which throws a org.hibernate.exception.SQLGrammarException: could not retrieve version:
because column SUB_ID does not exist on table SUPER.
Hibernate core 3.3.1, Anotations 3.3.1, EntityMnager 3.4
@Entity(name = "Company") @Table(name="COMPANY") @PrimaryKeyJoinColumn(name = "COMPANY_ID")
public class Company extends Party { ...
@Entity(name = "Party") @Table(name = "PARTY") @Inheritance(strategy = InheritanceType.JOINED) public class Party extends AbstractVersionedEntity implements EntityWithUUID {
private String key; @Id @GeneratedValue(generator="system-uuid") @GenericGenerator(name="system-uuid", strategy="uuid") @Column(name="PARTY_ID") public String getKey() { return key; }
public void setKey(String key) { this.key = key; }
@MappedSuperclass public abstract class AbstractVersionedEntity extends AbstractEntity implements VersionedEntity {
/** The version. */ private Integer version;
@Version @Column(name = "ROW_VERSION_SEQ") public Integer getVersion() { return version; } ...
Code:
Company company= entityManager.find(Company.class, "12345");
entityManager.lock(company, LockModeType.WRITE);
The generated SQL:
Hibernate: update PARTY set ROW_VERSION_SEQ=? where COMPANY_ID=? and ROW_VERSION_SEQ=?
|