2015-06-16 3 views
1

у меня есть проблемы с сессией в hibernate, ниже след ошибки:org.hibernate.HibernateException: Нет Hibernate Session привязан к нити, и конфигурация не позволяет создавать нетранзакционные один здесь

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); 
    } 

Основной метод:

@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); 


     } 

я уже пытался добавить @Transactional аннотацию к службе, к дао почти везде.

ответ

1

Включите Annotation based Transaction Management в свой конфигурационный файл Spring, добавив <tx:annotation-driven/>.

Here - хорошая ссылка, которую вы можете изучить.

+0

Спасибо, это швы, как я работаю – user2907386

Смежные вопросы