I have a spring integration hibernation application. My application captures files and checks their entries in the database. I use Hibernate for this.
I want to disable certain rows in the database. I retrieve rows using criteria. Editing a single field and using the saveorupdateall method. This does not change my db lines at all!
Below are snippets of code
<bean id="dmsdbDetectionJob" class="com.polling.scheduler.job.DMSDBDetectionJob">
</bean>
<bean id="dmsdbDetectionJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="dmsdbDetectionJob" />
<property name="targetMethod" value="deleteDBMaster" />
<property name="concurrent" value="false" />
</bean>
<bean id="simpleTriggerDB" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="dmsdbDetectionJobDetail" />
<property name="cronExpression" value="0 52 11 ? * *" />
</bean>
This is triggered at the set time. The deleteDBMaster method calls this code:
List<DocumentFile> strayFiles = documentDaoImpl.getStrayDocumentFiles();
try
{
if (strayFiles.size() > 0)
{
strayFiles = documentDaoImpl.softDelete(strayFiles, DocumentFile.class);
documentDaoImpl.saveOrUpdateAll(strayFiles);}
}...
SoftDelete uses generics
@Override
public <T extends GenericEntity> List<T> softDelete(List<T> stray,
Class<T> clazz)
{
for (T tObj : stray)
{
clazz.cast(tObj).setActive(Constants.INACTIVE.getVal());
}
return stray;
}
When I debug, I see the value changed in the active property of the objects in the strayFiles list, inside the saveOrUpdateAll () method. SaveOrUpdateAll method:
@Override
public void saveOrUpdateAll(Collection<?> objects) throws DMSException {
try {
for (Object object : objects) {
getCrntSession().saveOrUpdate(object);
}
} catch (final HibernateException e) {
throw new DMSException("Exception while save or update All ", ErrorCode.BASE_DB_ERROR, e);
}
}
When saveorupdate is called, no request is logged using hibernate. Nothing changes in db !!
spring, @Transactional . , spring . ? ?
, , ...
::
. , , .
@Override
@Transactional
public void softDeleteDocumentFile(
List<DocumentFile> stray)
{
for (DocumentFile tObj : stray)
{
tObj.setActive(Constants.INACTIVE.getVal());
saveEntity(tObj);
}
}
- . . Hibernate !!
, , - .
::
<mvc:annotation-driven />
<context:component-scan base-package="com.polling" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<context:property-placeholder location="classpath:config/jdbc.properties,classpath:config/config.properties,classpath:config/ftp.properties"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
>
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.polling.entity</value>
</list>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
::
hardcoded id. . , , , !
::
14:31:12.644 T|TransactionInterceptor |Completing transaction for [com.polling.service.DocumentServiceImpl.deActivateStrays]
14:31:12.644 T|TransactionInterceptor |Completing transaction for [com.polling.scheduler.job.DMSDBDetectionJob.deleteDBMaster]
14:31:12.675 T|HibernateTransactionManager |Triggering beforeCommit synchronization
14:31:12.675 T|HibernateTransactionManager |Triggering beforeCompletion synchronization
14:31:12.675 D|HibernateTransactionManager |Initiating transaction commit
14:31:12.675 D|HibernateTransactionManager |Committing Hibernate transaction on Session [SessionImpl(PersistenceContext[entityKeys=[EntityKey[com.polling.entity.DocumentFile
14:31:12.675 D|AbstractTransactionImpl |committing
14:31:12.675 T|SessionImpl |Automatically flushing session
14:31:12.675 T|AbstractFlushingEventListener |Flushing session
14:31:12.675 D|AbstractFlushingEventListener |Processing flush-time cascades
14:31:12.675 T|Cascade |Processing cascade ACTION_SAVE_UPDATE for: com.polling.entity.DocumentFile
14:31:12.675 T|Cascade |Done processing cascade ACTION_SAVE_UPDATE for: com.polling.entity.DocumentFile
14:31:12.675 T|Cascade |Processing cascade ACTION_SAVE_UPDATE for: com.polling.entity.DocumentFile
14:31:12.675 T|Cascade |Done processing cascade ACTION_SAVE_UPDATE for: com.polling.entity.DocumentFile
14:31:12.675 D|AbstractFlushingEventListener |Dirty checking collections
14:31:12.675 T|AbstractFlushingEventListener |Flushing entities and processing referenced collections
14:31:12.675 D|Collections |Collection found: [com.polling.entity.DocumentFile.docgroups
14:31:12.691 D|Collections |Collection found: [com.polling.entity.DocumentFile.docgroups
14:31:12.691 D|Collections |Collection found: [com.polling.entity.DocumentGroup.files
14:31:12.691 T|AbstractFlushingEventListener |Processing unreferenced collections
14:31:12.691 T|AbstractFlushingEventListener |Scheduling collection removes/(re)creates/updates
14:31:12.691 D|AbstractFlushingEventListener |Flushed: 0 insertions, 0 updates, 0 deletions to 3 objects
14:31:12.691 D|AbstractFlushingEventListener |Flushed: 0 (re)creations, 0 updates, 0 removals to 3 collections
14:31:12.691 D|EntityPrinter |Listing entities:
14:31:12.691 D|EntityPrinter |com.polling.entity.DocumentFile{encodingKey=yyy, docgroups=<uninitialized>, contactNumber=12121212, documentType=com.polling.entity.DocumentType
14:31:12.691 D|EntityPrinter |com.polling.entity.DocumentGroup{files=<uninitialized>, expiryPresent=false, modifiedBy=com.polling.entity.UserApplicationGroup
14:31:12.691 D|EntityPrinter |com.polling.entity.DocumentFile{encodingKey=azaz, docgroups=<uninitialized>, contactNumber=12121212, documentType=com.polling.entity.DocumentType
14:31:12.691 T|AbstractFlushingEventListener |Executing flush
14:31:12.691 T|JdbcCoordinatorImpl |Starting after statement execution processing [ON_CLOSE]
14:31:12.691 T|AbstractFlushingEventListener |Post flush
14:31:12.691 T|SessionImpl |before transaction completion
14:31:12.691 D|JdbcTransaction |committed JDBC Connection
14:31:12.691 D|JdbcTransaction |re-enabling autocommit
14:31:12.691 T|TransactionCoordinatorImpl |after transaction completion
14:31:12.707 T|SessionImpl |after transaction completion
14:31:12.707 T|HibernateTransactionManager |Triggering afterCommit synchronization
14:31:12.707 T|HibernateTransactionManager |Triggering afterCompletion synchronization
14:31:12.707 T|TransactionSynchronizationManager |Clearing transaction synchronization
14:31:12.707 T|TransactionSynchronizationManager |Removed value [org.springframework.orm.hibernate4.SessionHolder@711fbb66] for key [org.hibernate.internal.SessionFactoryImpl@5e2ed6a9] from thread [org.springframework.scheduling.quartz.SchedulerFactoryBean
14:31:12.707 T|TransactionSynchronizationManager |Removed value [org.springframework.jdbc.datasource.ConnectionHolder@67914078] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@7bc247d0] from thread [org.springframework.scheduling.quartz.SchedulerFactoryBean
14:31:12.707 D|HibernateTransactionManager |Closing Hibernate Session [SessionImpl(PersistenceContext[entityKeys=[EntityKey[com.polling.entity.DocumentFile
14:31:12.707 T|SessionImpl |Closing session
14:31:12.707 I|StatisticalLoggingSessionEventListener |Session Metrics {
36322379 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
16153296 nanoseconds spent preparing 2 JDBC statements;
20467177 nanoseconds spent executing 2 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
7830765 nanoseconds spent executing 1 flushes (flushing a total of 3 entities and 3 collections);
85953666 nanoseconds spent executing 2 partial-flushes (flushing a total of 2 entities and 2 collections)
}