2010-01-22 3 views
2

spring + hibernate에서 일반적인 오류가 발생했지만 해결할 수 없습니다. 나는 2 개 테이블이 일대 관계 :봄 OpenSessionInViewFilter : 개체를 저장할 수 없습니다.

<class name="Bsc" table="bsc"> 
    <id name="id" column="id"> 
     <generator class="native" /> 
    </id> 
    <property name="name" /> 
    <set name="cells"> 
     <key column="bsc_id" /> 
     <one-to-many class="Cell" /> 
    </set> 
</class> 

    <class name="Cell" table="cell"> 
    <id name="id" column="id"> 
     <generator class="native" /> 
    </id> 
    <property name="name" column="name" /> 
    <many-to-one name="bsc" column="bsc_id" not-null="true" /> 
</class> 

내 DAO :

public class BscDaoImpl extends HibernateDaoSupport implements BscDao { 

@Override 
public Bsc get(int id) { 
    return (Bsc) getHibernateTemplate().get(Bsc.class, id); 
} 

@Override 
public void save(Bsc bsc) { 
    getHibernateTemplate().saveOrUpdate(bsc); 
} 
} 

내 컨트롤러 :

BSC 많은

내 최대 절전 모드 설정을

public class BscFormController extends SimpleFormController { 

private BscDao bscDao; 

public void setBscDao(BscDao bscDao) { 
    this.bscDao = bscDao; 
} 

protected Object formBackingObject(HttpServletRequest request) 
     throws Exception { 
    String id = request.getParameter("id"); 

    if (!StringUtils.isBlank(id)) { 
     return bscDao.get(new Integer(id)); 
    } 

    return new Bsc(); 
} 

public ModelAndView onSubmit(HttpServletRequest request, 
     HttpServletResponse response, Object command, BindException errors) 
     throws Exception { 

    Bsc bsc = (Bsc) command; 
    String success = getSuccessView(); 

    bscDao.save(bsc); 

    return new ModelAndView(success); 
} 
} 

보시려면, bsc 정보를 작성/편집 할 수있는 양식이 있습니다. 또한, 나는이 BSC의 모든 셀을 나열하려면, 그래서 web.xml의 게으른 부하를 config (설정)

<filter> 
    <filter-name>openSessionInViewFilter</filter-name> 
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
    <init-param> 
     <param-name>singleSession</param-name> 
     <param-value>true</param-value> 
    </init-param> 
    <init-param> 
     <param-name>flushMode</param-name> 
     <param-value>AUTO</param-value> 
    </init-param> 
    <init-param> 
     <param-name>sessionFactoryBeanName</param-name> 
     <param-value>mySessionFactory</param-value> 
    </init-param> 
</filter> 

내 문제 : 나는 제거하면 저장을 누릅니다 버튼 (이 확인 저장할 때 내가 객체를 저장할 수 없습니다 OpenSessionInViewFilter 설정).


나는 TransactionManager에의 설정 추가 :

<bean id="transactionManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="mySessionFactory"/> 
</bean> 

를하지만 여전히 작동하지 않습니다. 내가 뭐 놓친 거 없니 ?

답변

1

Spring 애플리케이션 컨텍스트에서 TransactionManager를 구성 했습니까? 당신이 JDK5 +에 있다면 그런데 은, 당신은 (당신이 2 배 코드 크기를 줄일 수 있습니다)를보다 효율적으로 사용 주석을 거라고

+0

는 내가 제이 보스 서버를 사용 및 제이보스의 최대 절전 모드로 주석 충돌을 최대 절전 모드. xml config (?)보다 주석이 느린 것을 볼 수 있습니다. – QuanNH

+0

TransactionManager 설정을 추가했습니다. 하지만 여전히 작동하지 않습니다. 나는 무엇인가 놓친다? – QuanNH

0

내 현재 설정

web.xml을

<!-- lazyLoad--> 
<filter> 
    <filter-name>openSessionInViewFilter</filter-name> 
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
    <init-param> 
     <param-name>singleSession</param-name> 
     <param-value>true</param-value> 
    </init-param> 
    <init-param> 
     <param-name>sessionFactoryBeanName</param-name> 
     <param-value>mySessionFactory</param-value> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>openSessionInViewFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

스프링 설정

<bean id="transactionManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="mySessionFactory" /> 
</bean> 

<aop:config> 
    <aop:advisor pointcut="execution(* vn.com.vhc.cbs.dao.*.*(..))" 
     advice-ref="txAdvice" /> 
</aop:config> 

<tx:advice id="txAdvice"> 
    <tx:attributes> 
     <tx:method name="save*" /> 
     <tx:method name="update*" /> 
     <tx:method name="remove*" /> 
     <tx:method name="*" read-only="true" /> 
    </tx:attributes> 
</tx:advice> 

희망이 도움

1

동일한 문제가 발생했기 때문에 여기에 있습니다. session.save (아무거나)가 실제로 데이터를 데이터베이스에 유지하지 못하는 것 같습니다. 디버그 로깅에는 많은 선택 사항이 표시되지만 업데이트 또는 삽입은 표시되지 않습니다.

save() 또는 update() 또는 다른 메서드 다음에 session.flush()를 호출하면 업데이트가 강제로 데이터베이스에 푸시됩니다.

왜 이렇게해야합니까? 내가 아직 알아 내지 못한 이유가 무엇입니까? 결국 모든 업데이트가 커밋되기 전에 데이터베이스로 이동하기를 원한다고 생각했을 것입니다.

내가 알아 내려고하는 것은 flushmode를 설정하여 마지막 커밋 전에 flush() 메서드가 있는지 확인하는 것입니다. 아직 시도한 것은 없으며 명시 적 플러시 콜이 여전히 필요합니다.

2

웹에서 OpenSessionInViewFilter를 설정하여 해결했습니다.XML

<filter> 
     <filter-name>lazyLoadingFilter</filter-name> 
     <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
      <init-param> 
      <param-name>flushMode</param-name> 
      <param-value>AUTO</param-value> 
     </init-param> 
</filter> 

안부

관련 문제