1

I have problem with session in hibernate, below is the error trace:

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)
at ptv.generic.dao.AbstractGenericSearchDaoHibernateImpl.findByQuery(AbstractGenericSearchDaoHibernateImpl.java:327)
at ptv.generic.dao.AbstractGenericSearchDaoHibernateImpl.findByQuery(AbstractGenericSearchDaoHibernateImpl.java:311)
at ptv.drm.dao.impl.RightsProfileHibernateDao.findByLookupName(RightsProfileHibernateDao.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy50.findByLookupName(Unknown Source)
at ptv.media.ingest.processor.CmsXMLIngestUpdateServiceImpl.verifyProfilesRightsRelation(CmsXMLIngestUpdateServiceImpl.java:1104)
at ptv.media.ingest.processor.CmsXMLIngestUpdateServiceImpl.addNewMediaContent(CmsXMLIngestUpdateServiceImpl.java:659)
at ptv.media.ingest.processor.CmsXMLIngestUpdateServiceImpl.insert(CmsXMLIngestUpdateServiceImpl.java:296)
at ptv.media.ingest.processor.AbstractCmsXMLIngestFileStrategy.insertNewMediaContent(AbstractCmsXMLIngestFileStrategy.java:251)
at ptv.media.ingest.processor.CmsXMLIngestFileUnencodedStrategy.insert(CmsXMLIngestFileUnencodedStrategy.java:74)
at ptv.media.autoingest.service.AutoIngestServiceImpl.ingestObtainedFiles(AutoIngestServiceImpl.java:1661)
at ptv.media.autoingest.service.AutoIngestServiceImpl.process(AutoIngestServiceImpl.java:138)
at ptv.media.TestAutoIngest.main(TestAutoIngest.java:19)

applicationContext:

<bean id="drmDaoProxyCreator"
        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <description>Automatically wraps all the specified bean(s) with a
            transaction layer
        </description>
        <property name="proxyTargetClass" value="false" />
        <property name="beanNames">
            <list>
                <value>rightsProfileDAO</value>

            </list>
        </property>
        <property name="interceptorNames">
            <list>
                <value>drmTxInterceptor</value>
            </list>
        </property>
    </bean>


    <bean id="drmTransactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <description>DRM transaction manager</description>
      <property name="sessionFactory" ref="drmOwnerSessionFactory" /> 
     </bean>

     <bean id="drmTxInterceptor"
        class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <description>DRM transaction interceptor</description>
        <property name="transactionManager" ref="drmTransactionManager" />
        <property name="transactionAttributeSource">
            <bean
                class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
        </property>
    </bean>

    <bean id="rightsProfileDAO" class="ptv.drm.dao.impl.RightsProfileHibernateDao">
        <description>Data access object for accessing RIGHTS_PROFILE table
        </description>
        <property name="sessionFactory" ref="drmOwnerSessionFactory" />
    </bean>

RightsProfileHibernateDao

/**
     * {@inheritDoc}
     */
    @Override
    public RightsProfile findByLookupName(final String lookupName) {
        final List<RightsProfile> result = findByQuery("from RightsProfile where lookupName = :lookupName", new String[] { "lookupName" },
                new Object[] { lookupName });
        return CollectionUtils.isEmpty(result) ? null : result.get(0);
    }

Main method:

   @Transactional
        private Pair<String, Boolean> ingestObtainedFiles(final Integer orgnId) {

            try {
                folder = ftpAccountService.getMonitoringFolderByOrgnId(orgnId);
                final List<File> clientsXMLFiles = scanFTPFolderForXmlFiles(new File(
                        folder.getProcessingDirectory()));
                // Sort files, so they will be processed from oldest to newest.
                // Added for AutoIngestService to work properly.
                Collections.sort(clientsXMLFiles, new Comparator<File>() {
                    @Override
                    public int compare(final File file1, final File file2) {
                        return Long.valueOf(file1.lastModified()).compareTo(
                                file2.lastModified());
                    }
                });

                for (final File messageFile : clientsXMLFiles) {
                    LOGGER.debug("Processing file " + messageFile.getAbsolutePath());

                    final Assets assets = getIngestXMLUnMarshaler(messageFile);
                    // process it. Intercept it so we begin transaction.
                    getCmsXMLIngestFileUnencodedStrategy().insert(assets, folder, messageFile);

                }
            } catch (final Exception e) {
                LOGGER.error("Error when ingesting files" ,e);
            }
            return new Pair<String, Boolean>(folder.toString(), true);


      }

I already tried to add the @Transactional annotation to the service, to the dao almost everywhere.

0

1 Answer 1

1

Enable Annotation based Transaction Management in your Spring configuration file by adding<tx:annotation-driven/>.

Here is a good link which you can look into.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.