2012-05-18 5 views
0

나는 정말로 이상한 문제가있다. 봄 + 최대 절전 모드를 사용하는 애플리케이션을 작성했다. 내 최대 절전 모드의 구성은 다음과 같다 :Hibernate 트랜잭션이 작동하지 않는다.

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> 

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="placeholderPrefix" value="${hospital_"/> 
     <property name="location" value="hospital.properties"/> 
    </bean> 

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 
     <property name="driverClass"       value="${hospital_hibernate.driverClassName}"/> 
     <property name="jdbcUrl"        value="${hospital_hibernate.url}"/> 
     <property name="user"         value="${hospital_hibernate.username}"/> 
     <property name="password"        value="${hospital_hibernate.password}"/> 
     <!-- 
     <property name="acquireIncrement"      value="20"/> 
     <property name="acquireRetryAttempts"     value="30"/> 
     <property name="acquireRetryDelay"      value="1000"/> 
     <property name="autoCommitOnClose"      value="true"/> 
     <property name="checkoutTimeout"     value="10000"/> 
     <property name="debugUnreturnedConnectionStackTraces" value="true"/> 
     <property name="idleConnectionTestPeriod"    value="100"/> 
     <property name="initialPoolSize"      value="1"/> 
     <property name="maxConnectionAge"      value="1000"/> 
     <property name="maxConnectionAge"      value="1000000"/> 
     <property name="maxIdleTime"       value="200"/> 
     <property name="maxIdleTimeExcessConnections"   value="3600"/> 
     <property name="maxPoolSize"       value="10"/> 
     <property name="minPoolSize"       value="1"/> 
     <property name="preferredTestQuery"      value="select 1"/> 
     <property name="testConnectionOnCheckin"    value="false"/> 
     <property name="unreturnedConnectionTimeout"   value="1000"/> 
     --> 
    </bean> 

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
     <property name="dataSource"  ref="dataSource"/> 
     <property name="schemaUpdate" value="${hospital_schema.update}"/> 
     <property name="mappingResources"> 
      <list> 
       <value>com/saman/entity/hbms/Employee.hbm.xml</value> 
       <value>com/saman/entity/hbms/Shift.hbm.xml</value> 
       <value>com/saman/entity/hbms/Patient.hbm.xml</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${hospital_hibernate.dialect}</prop> 
       <prop key="hibernate.show_sql">${hospital_hibernate.showsql}</prop> 
       <!--<prop key="hibernate.hbm2ddl.auto">update</prop>--> 
       <prop key="hibernate.generate_statistics">true</prop> 

       <!--<prop key="hibernate.cache.use_second_level_cache">true</prop>--> 
       <!--<prop key="hibernate.cache.use_query_cache">true</prop>--> 
       <!--<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</prop>--> 
       <!--<prop key="net.sf.ehcache.configurationResourceName">ehcache.xml</prop>--> 

       <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> 
       <prop key="hibernate.use_sql_comments">true</prop> 

       <prop key="hibernate.transaction.auto_close_session">true</prop> 

      </props> 
     </property> 
     <property name="eventListeners"> 
      <map> 
       <entry key="merge"> 
        <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/> 
       </entry> 
      </map> 
     </property> 
    </bean> 

    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory"/> 
     <!--<property name="prepareConnection" value="true"/>--> 
     <!--<property name="hibernateManagedSession" value="true"/>--> 
    </bean> 

</beans> 

나는 또한 나의 텍사스을 설정

<tx:advice id="txAdvice" transaction-manager="txManager"> 
    <tx:attributes> 
     <tx:method name="get*" propagation="REQUIRED" read-only="true"/> 
     <tx:method name="*" rollback-for="java.lang.Throwable"/> 
    </tx:attributes> 
</tx:advice> 


<aop:config> 
    <aop:pointcut id="transactionServiceOperation" 
        expression="execution(* com.saman.svc.dalc.IEmployeeDA.*(..))"/> 
    <aop:pointcut id="transactionServiceOperation2" 
        expression="execution(* com.saman.svc.dalc.IPatientDA.*(..))" /> 
    <aop:pointcut id="transactionServiceOperation3" 
        expression="execution(* com.saman.svc.dalc.IShiftDA.*(..))"/> 
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionServiceOperation"/> 
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionServiceOperation2"/> 
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionServiceOperation3"/> 
</aop:config> 

내가 10 또는 11 데이터베이스, 내 응용 프로그램을 실행할 때이 액세스 여기에 문제가 있음 : 조언을 아래와 같이 그것은 잘 작동하지만, 그 후, 내 응용 프로그램이 잠겨 응답하지 않는 것 같습니다.

나는 정말로 어디에 문제가 있는지 알지 못합니다.

p.s. 필자는 모든 DA를 IPatientDA, IShiftD 및 IEmployeeDA를 상속하는 patientDA, shiftDA 및 employeeDA 클래스로 정의합니다.

내 GenericDA :

public class GenericDA<TEntity, TId extends Serializable> extends HibernateDaoSupport implements IGenericDA<TEntity, TId> 
{ 
    private Boolean isDateString = false; 
    private Dialect mappingDialect = Dialect.mysql; 

    public Boolean isDateString() 
    { 
     return isDateString; 
    } 

    public void setDateString(Boolean dateString) 
    { 
     isDateString = dateString == null ? false : dateString; 
    } 

    public Dialect getMappingDialect() 
    { 
     return mappingDialect; 
    } 

    public Dialect dialect() 
    { 
     return this.getMappingDialect(); 
    } 

    public void setMappingDialect(Dialect mappingDialect) 
    { 
     this.mappingDialect = mappingDialect; 
    } 

    public Class getType() 
    { 
     Type tClass = null; 
     Type type = this.getClass().getGenericSuperclass(); 
     if (type instanceof ParameterizedType) 
     { 
      ParameterizedType paramType = (ParameterizedType) type; 
      tClass = paramType.getActualTypeArguments()[0]; 
     } 
     return (Class) tClass; 
    } 

    public String getStringType() 
    { 
     return this.getType().getName(); 
    } 

    public TEntity get(TId id) 
    { 
     return (TEntity) this.getSession().get(getType(), id); 
    } 

    public List<TEntity> get() 
    { 
     return (List<TEntity>) this.getSession().createCriteria(getType()).list(); 
    } 

    public List<TEntity> get(long from, long size) 
    { 
     return this.getSession().createCriteria(getType()) 
       .setFirstResult((int) from) 
       .setMaxResults((int) size) 
       .list(); 
    } 

    public TEntity insert(TEntity entity) 
    { 
     this.getSession().save(entity); 
     return entity; 
    } 

    public TEntity update(TEntity entity) 
    { 
     try 
     { 
      this.getSession().evict(entity); 
      this.getSession().update(entity); 
      //this.getSession().flush(); 
     } 
     catch (HibernateException ex) 
     { 
      this.getSession().evict(entity); 
      this.getSession().clear(); 
//   this.getSession().update(entity); 
      throw ex; 
     } 
     return entity; 
    } 

    public void delete(TId id) 
    { 
     this.getSession().delete(get(id)); 
    } 

    public void delete(TEntity entity) 
    { 
     this.getSession().delete(entity); 
    } 

    public List<TEntity> get(int from, int size) 
    { 
     //noinspection unchecked 
     return this.getSession().createCriteria(getType()) 
       .setFirstResult(from) 
       .setMaxResults(size) 
       .list(); 
    } 

    public long getCount() 
    { 
     return (Long) this.getSession().createQuery("select count(entity.id) from " + getStringType() + " entity") 
       .uniqueResult(); 
    } 

    public Object getProperty(Long id, String property) 
    { 
     Criteria criteria = this.getSession().createCriteria(getType()); 
     criteria.add(Restrictions.eq("id", id)); 
     criteria.setProjection(Projections.property(property)); 
     criteria.setMaxResults(1); 
     return criteria.uniqueResult(); 
    } 

    public org.hibernate.Session prepareFilteredSession(Date effectiveDate) 
    { 
     org.hibernate.Session session = this.getSession(); 
     if (effectiveDate != null) 
      session.enableFilter("effectiveDate").setParameter("fDate", effectiveDate); 

     return session; 
    } 

    public void DisableFilter(org.hibernate.Session session) 
    { 
     session.disableFilter("effectiveDate"); 
    } 

    public String getLikeExpression(String filter, String parameter) 
    { 
     String result = "LIKE"; 
     if (filter.startsWith("*")) 
     { 
      if (this.mappingDialect.equals(Dialect.oracle)) 
       result += " '%' ||"; 
      else 
       result += " '%' +"; 
     } 

     result += " :" + parameter + " "; 
     if (filter.endsWith("*")) 
     { 
      if (this.mappingDialect.equals(Dialect.oracle)) 
       result += " || '%'"; 
      else 
       result += " + '%'"; 
     } 
     return result; 
    } 

    public String getLikeParameter(String parameter) 
    { 
     if (parameter.startsWith("*")) 
      parameter = parameter.substring(1); 

     if (parameter.endsWith("*")) 
      parameter = parameter.substring(0, parameter.length() - 1); 

     return parameter; 
    } 

    public Query setDateParameter(Query query, String name, Date value) 
    { 
     if (this.isDateString) 
      return query.setString(name, String.format("%1$tY-%1$tm-%1$td %tT", value)); 
     else 
      return query.setParameter(name, value); 

    } 
} 

예를 들어 내 ShiftDA의 예는 다음과 같습니다

public class ShiftDA extends GenericDA<ShiftEntity, Long> implements IShiftDA { 

    public void updateNumberOfPatients(int numberOfPatients, Long columnID){ 
     try{ 
      Statement st = this.getSession().connection().createStatement(); 
      String sql = "UPDATE shift SET CurrentNumberOfPatients='" + numberOfPatients + "' WHERE ShiftId='" + columnID.toString() + "' "; 
      st.executeUpdate(sql); 

     }catch(Exception e){ 
      e.printStackTrace(); 
     } 

    } 

} 

답변

1

이 C3P0 설정에 의해 판단 (분 = 1 개 최대 = 10)와 당신이 가지고있는 10 개 또는 11 요청 내가 뭔가를 추측하지 않기 때문에 당신이 연결 풀을 소진하고 있다고 추측하고 말할 것입니다. 나는 이것이 tx-manager와 관련이 있으며 세션의 수명이 끝났을 때 알지 못한다고 생각합니다.

또한 - 저는 C3P0보다는 commons DBCP를 사용합니다.

DA 개체가 수행중인 작업을 게시 할 수 있습니까?

+0

나는 또한 나의 DA를 포함했습니다. – saman

+0

catch 블록을 {} finally {stmt.close(); } 나는 그것이 연결을 열고 수영장을 소진하고 있다고 생각합니다. – Dan

관련 문제