0
在下面的代碼中,當我調用方法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();
}
}
什麼是結果查詢?什麼是您的事務隔離級別? –