更新到hibernate后4.3.6保存(实体)不起作用。在更新之前保存看起来像:
public void save(Object entity) {
getHibernateTemplate().save(entity);
}
它运作得很好。 现在它:
public void save(Object entity) {
getCurrentSession().save(entity);
}
它并没有保存实体。 Hibernate实体和地图是相同的。没有任何改变。 问题是当我试图保存实体时,然后我使用ibatis调用存储过程,这需要在DB(Oracle)之前保存实体。数据库中没有数据,因此我的程序崩溃了。
我的问题:hibernate-core 4.3.6有什么问题,这个版本不像hibernate-core 3.5.6(我以前的版本)那样工作。除保存呼叫外,代码无变化。只有图书馆。
当我在调试模式下执行save时:
2014-10-29 11:35:31,820 Thread-8 SessionFactoryImpl$SessionBuilderImpl- Opening Hibernate Session. tenant=null, owner=null
2014-10-29 11:35:31,823 Thread-8 SessionImpl- Setting flush mode to: MANUAL
2014-10-29 11:35:31,862 Thread-8 DefaultSaveOrUpdateEventListener- Saving transient instance
2014-10-29 11:35:31,865 Thread-8 AbstractSaveEventListener- Generated identifier: 10107, using strategy: org.hibernate.id.Assigned
2014-10-29 11:35:31,868 Thread-8 AbstractSaveEventListener- Saving pl.com.uhc.db.hibernates.dto.ster.Message#10107
2014-10-29 11:35:31,871 Thread-8 ActionQueue- Adding an EntityInsertAction for [pl.com.uhc.db.hibernates.dto.ster.Message] object
2014-10-29 11:35:31,874 Thread-8 ActionQueue- Adding insert with no non-nullable, transient entities: [EntityInsertActionpl.com.uhc.db.hibernates.dto.ster.Message#10107]
2014-10-29 11:35:31,877 Thread-8 ActionQueue- Adding resolved non-early insert action.
2014-10-29 11:35:31,880 Thread-8 IdentifierValue$4- ID unsaved-value strategy UNDEFINED
2014-10-29 11:35:31,883 Thread-8 AbstractEntityPersister- Getting current persistent state for: pl.com.uhc.db.hibernates.dto.ster.MessageType#1
Hibernate:
select
messagetyp_.MessageTypeID,
messagetyp_.FullName as FullName2_115_,
messagetyp_.ShortName as ShortName3_115_,
messagetyp_.Type as Type4_115_
from
MessageType messagetyp_
where
messagetyp_.MessageTypeID=?
2014-10-29 11:35:31,891 Thread-8 LogicalConnectionImpl- Obtaining JDBC connection
2014-10-29 11:35:31,894 Thread-8 LogicalConnectionImpl- Obtained JDBC connection
2014-10-29 11:35:31,897 Thread-8 JdbcCoordinatorImpl- Registering statement [oracle.jdbc.driver.OraclePreparedStatementWrapper@133c3e0]
2014-10-29 11:35:31,900 Thread-8 BasicBinder- binding parameter [1] as [INTEGER] - [1]
2014-10-29 11:35:31,906 Thread-8 JdbcCoordinatorImpl- Registering result set [oracle.jdbc.driver.OracleResultSetImpl@180ca9e]
2014-10-29 11:35:31,909 Thread-8 BasicExtractor- extracted value ([FullName2_115_] : [VARCHAR]) - [Komunikat statystyczny zwrotny[SWZ]]
2014-10-29 11:35:31,912 Thread-8 BasicExtractor- extracted value ([ShortName3_115_] : [VARCHAR]) - [SWZ]
2014-10-29 11:35:31,914 Thread-8 BasicExtractor- extracted value ([Type4_115_] : [VARCHAR]) - [P_SWI]
2014-10-29 11:35:31,917 Thread-8 JdbcCoordinatorImpl- Releasing result set [oracle.jdbc.driver.OracleResultSetImpl@180ca9e]
2014-10-29 11:35:31,920 Thread-8 JdbcCoordinatorImpl- Closing result set [oracle.jdbc.driver.OracleResultSetImpl@180ca9e]
2014-10-29 11:35:31,924 Thread-8 JdbcCoordinatorImpl- Releasing statement [oracle.jdbc.driver.OraclePreparedStatementWrapper@133c3e0]
2014-10-29 11:35:31,928 Thread-8 JdbcCoordinatorImpl- Closing prepared statement [oracle.jdbc.driver.OraclePreparedStatementWrapper@133c3e0]
2014-10-29 11:35:31,931 Thread-8 JdbcCoordinatorImpl- Starting after statement execution processing [ON_CLOSE]
2014-10-29 11:35:31,934 Thread-8 UnresolvedEntityInsertActions- No unresolved entity inserts that depended on [pl.com.uhc.db.hibernates.dto.ster.Message#10107]
2014-10-29 11:35:31,937 Thread-8 UnresolvedEntityInsertActions- No entity insert actions have non-nullable, transient entity dependencies.
答案 0 :(得分:0)
将@Transactional添加到方法中:
@Transactional
public void save(Object entity) {
getCurrentSession().save(entity);
}
Hibernate需要一个事务来创建会话。添加此注释后,保存开始起作用。