2016-03-22 15 views
0

JAX-RS api için Spring 4/Hibernate4 kullanıyorum. Ben Methode olsun çağrı zaman org.hibernate.SessionException girmek: Oturum Not kapalıdır: Zaten @Transactional ile servis ve dao Methode açıklama çalıştım amaJPA Spring Hazırda Bekletme Rest API hatası Oturum kapatıldı

çalışmıyor Benim bağlam ben

@PersistenceContext(unitName = "ppRestPersistenceLegacy") 
private EntityManager entityManager; 

public List<RcPosStatus> getRcPosStatus(String orderByInsertionDate) { 

    String sqlString = null; 
    if(orderByInsertionDate != null){ 
     sqlString = "SELECT s FROM RcPosStatus s" + " WHERE ROWNUM < 11 ORDER BY s.DATE_FROM " + orderByInsertionDate; 
    } else { 
     sqlString = "SELECT s FROM RcPosStatus s WHERE ROWNUM < 11"; 
    }   
    TypedQuery<RcPosStatus> query = entityManager.createQuery(sqlString, RcPosStatus.class);   
    return query.getResultList(); 

} 

hizmetim l var benim DAO bu

<bean id="ppEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="persistenceXmlLocation" value="classpath:config/persistence-demo.xml" /> 
    <property name="persistenceUnitName" value="ppRestPersistenceLegacy" />   
    <property name="dataSource" ref="ppRestLegacyDS" /> 
    <property name="packagesToScan" value="fr.test.rest*" /> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
      <property name="showSql" value="true" /> 
      <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" /> 
     </bean> 
    </property> 
</bean> 
<bean id="ppRestLegacyDS" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton"> 
    <property name="jndiName" value="java:comp/env/jdbc/ppRestLegacyDB" /> 
    <property name="resourceRef" value="true" />   
</bean> 

benziyor Bu

@Autowired 
BufferDao bufferDao; 


// ******************** Read related methods implementation **********************  
public List<Buffer> getBuffers(String orderByInsertionDate, Integer numberDaysToLookBack) throws AppException { 

    if(isOrderByInsertionDateParameterValid(orderByInsertionDate)){ 
     throw new AppException(Response.Status.BAD_REQUEST.getStatusCode(), 400, "Please set either ASC or DESC for the orderByInsertionDate parameter", null , AppConstants.BLOG_POST_URL); 
    }   
    List<Buffer> buffers = bufferDao.getBuffers(orderByInsertionDate); 

    return buffers; 
} 

ve sonda gelen benim kaynak

@GET 
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) 
public List<RcPosStatus> getRcPosStatus(
     @QueryParam("orderByInsertionDate") String orderByInsertionDate, 
     @QueryParam("numberDaysToLookBack") Integer numberDaysToLookBack) 
     throws IOException, AppException { 
      List<RcPosStatus> status = statusService.getRcPosStatus(
      orderByInsertionDate, numberDaysToLookBack); 
    return status; 
} 

cevap

0

gibi ooks @Transactional

ile hizmet Methode başvurum bağlamında

<tx:annotation-driven transaction-manager="transactionManager" /> 
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="ppEntityManagerFactory" /> 
</bean> 

için ek açıklama fasulye ekleyerek Ve açıklamalar ekleyerek sorunu çözüldü

 // ******************** Read related methods implementation **********************  
@Transactional 
public List<RcPosStatus> getRcPosStatus(String orderByInsertionDate, Integer numberDaysToLookBack) throws AppException { 
İlgili konular