在下面的代码中,当我调用 EntityADAO.findByGroupId(...) 方法时,表 EntityA 被锁定,直到事务完成。我不想要这个。如何避免表锁定?提前致谢。
My database is SQL SERVER 2012. I am suing Hibernate 4.0.2.
以下是代码摘录:
@Entity
@Table(name = EntityA)
@NamedQueries ({
@NamedQuery(name="EntityA.findByGroupId", query="SELECT p FROM EntityA p WHERE p.groupId= :groupId")})
public class EntityA implements Serializable {
@Id
@Column(name = "EntityKey", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long entityKey;
@Version
@Column(name = "Version", nullable = false)
private Long version = -1l;
@NotNull
@Column(name = "GroupId")
private Integer groupId;
}
@Repository("EntityA")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class EntityADAO extends AbstractJpaDAO<EntityA> {
@PersistenceContext
protected EntityManager em;
public EntityADAO() {
setClazz(EntityADAO.class);
}
**//A call to this method locks the table EntityA until the transaction is complete**
public List<EntityA> findByGroupId(int groupId) {
TypedQuery<EntityA> query = em.createNamedQuery("EntityA.findByGroupId", EntityA.class);
query.setParameter("groupId", groupId);
return query.getResultList();
}
}