我正在使用Weblogic 10.3.6 + Hibernate 3和EJB 3.0
我正在尝试更新实体,但它没有在数据库中更新。 没有例外
请找到hibernate配置文件,如下所示
<property name="hibernate.connection.datasource">jdbc/wfAR_ConnectionDS</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.hibernate.session_factory_name">wfAR_ConnectionDS</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.transaction.factory.class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.transaction.auto_close_session">false</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.format_sql">true</property>
我正在使用以下代码更新EJB中的实体
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public long updateCustomerData(ArCatCustomer customer){
long id=-1;
Session session = sessionFactory.openSession();
try{
System.out.println("**************Trying to Update***********");
session.update(customer);
//session.evict(customer);
session.flush();
System.out.println("***********Update Finished***********");
}catch(RuntimeException runExp){
runExp.printStackTrace();
throw runExp;
} finally{
session.close();
}
return id;
}
我可以在控制台中看到以下内容:
**************Trying to Update***********
Hibernate:
/* update
com.ar.flextronics.model.ArCatCustomer */ update
AR_catCustomer
set
SegmentID=?,
MepID=?,
ParentCustomerID=?,
CustomerNumber=?,
CustomerName=?,
VendorID=?,
LocalVATID=?,
[FlexCustomer-Supplier]=?,
VMI=?,
TypeOfBilling=?,
CreditTerms=?,
CustomerCurrencyID=?,
CreditRate=?,
CreditLimit=?,
ParentBPNumInsideCompany=?,
LegalEntityname=?,
Region=?,
Active=?,
ERPName=?,
ERPServer=?,
ERPFinanceCompanyNumber=?,
ERPLogisticCompanyNumber=?,
LastUpdate=?,
UpdatedBy=?,
CustomerTypeID=?
where
CustomerID=?
***********Update Finished***********
但是数据没有保存在数据库中。
请帮我解决。感谢
答案 0 :(得分:7)
我在你的hibernate配置属性中看不到:
<property name="hibernate.connection.autocommit">true</property>
由于默认配置= false。设置此项并检查结果。
但如果您想手动执行此操作,则需要:
Transaction tx = session.beginTransaction();
//your code
tx.commit();
session.close();