嗨:我是hibernate的新手,我正在尝试加载已经存在于DB中的订单,更改字段然后更新订单但是我遇到了以下异常:“org.hibernate.exception .LockTimeoutException:无法执行语句“。 (必须说我不改变订单的行)
public static void closeOrder(Integer idOrder) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try
{
tx = session.beginTransaction();
Order order = (Order) session.load(Order.class, idOrder);
order.setDate (new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
session.flush();
tx.commit();
}
catch(Exception e)
{
if(tx != null)
{
tx.rollback();
}
e.printStackTrace();
}
finally
{
session.close();
}
}
Hibernate映射: Order.hbm.xml
<hibernate-mapping package="com.Pojos">
<class name="Order" table="Order">
<id name="idOrder" type="int" column="idOrder">
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="sequence_name">Order_SEQ</param>
<param name="initial_value">1</param>
<param name="increment_size">1</param>
<param name="value_column">CurrentValue</param>
<param name="optimizer">hilo</param>
</generator>
</id>
<property name="date"/>
<many-to-one name="client" column="idClient" class="Clients"/>
<list name="orderLines" table="OrderLines">
<key column="idOrder"/>
<index column="idx"/>
<one-to-many class="OrderLines"/>
</list>
</class>
</hibernate-mapping>
OrderLines.hbm.xml
<hibernate-mapping package="com.Pojos">
<class name="OrderLines" table="OrderLines">
<id name="idOrderLine" type="int" column="idOrderLine">
<generator class="increment"/>
</id>
<many-to-one name="order" column="idOrder" not-null="true"/>
</class>
</hibernate-mapping>
注意:当我创建一个新订单时,添加一些行并保存它我没有问题。
我做错了什么?