EntityManager will not PESSIMISTIC lock a parent class of JOINED inheritance
----------------------------------------------------------------------------
Key: HHH-7315
URL:
https://hibernate.onjira.com/browse/HHH-7315
Project: Hibernate ORM
Issue Type: Bug
Components: entity-manager
Affects Versions: 4.1.3, 4.1.2
Environment: Hibernate 4.1.2, 4.1.3, PostgreSQL 9.1
Reporter: Bryan Varner
Given a JPA class Hierarchy like:
{code}
@Entity(name = "BaseThing")
@Table(name = "BaseThing")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class BaseThing implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"BaseThing_id_seq")
@SequenceGenerator(name = "BaseThing_id_seq", sequenceName =
"BaseThing_id_seq", allocationSize = 50)
@Column(name = "id", nullable = false)
private Long id;
@Basic(optional = false)
@Column(name = "name", nullable = false, length = 48)
private String name;
@Version
@Column(name = "version")
private int version;
...
}
@Entity(name = "ConcreteThing")
@Table(name = "ConcreteThing")
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
public class ConcreteThing extends BaseThing {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
@Column(name = "aprop", nullable = false, length = 12)
private String aProp;
...
}
@Entity(name = "AnotherConcreteThing")
@Table(name = "AnotherConcreteThing")
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
public class AnotherConcreteThing extends BaseThing {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
@Column(name = "anotherprop", nullable = false, length = 12)
private String anotherProp;
...
}
{code}
Invoking the following code fails to generate a query with a FOR UPDATE clause.
{code}
entityManager.find(BaseThing.class, 0, LockModeType.PESSIMISTIC_WRITE);
{code}
Inspecting the LockMode on the returned object results in the following behavior...
{code}
BaseThing obj = entityManager.find(BaseThing.class, 0, LockModeType.PESSIMISTIC_WRITE);
// The PESSIMISTIC_WRITE lock requirement is totally ignored, and the object is returned
with OPTIMISTIC.
// If you try to promote the lock to PESSIMISTIC_WRITE...
if (entityManager.getLockMode(obj).equals(LockModeType.OPTIMISTIC)) {
entityManager.lock(obj, LockModeType.PESSIMISTIC_WRITE);
}
// It looks like it's succesfull
if (entityManager.getLockMode(obj).equals(LockModeType.PESSIMISTIC_WRITE)) {
System.out.println("Hurray!");
}
// HOWEVER... There's not any SQL generated. AT ALL, by the lock() method, and there
is no lock in the database.
{code}
So I suppose this bug it two-fold.
1.) You can't get a PESSIMISTIC lock on anything that results in a left outer join to
get the polymorphic query results.
2.) You can't promote the optimistic locks for those polymorphic objects into a
PESSIMISTIC lock.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira