LazyInitializationException, obwohl openSessionInViewInterceptor

Ich habe ein problem mit LazyInitializationException obwohl ich mit openSessionInViewInterceptor. Ich habe gelesen, so viele posts über dieses Thema und ich habe versucht, drei oder vier verschiedene Herangehensweisen.

Erste Sache ist, dass ich nicht wollen, um die Einstellung auf false ist, wird der lazzy-Attribut in der Hibernate-Konfiguration-Datei. Also, ich möchte eine tatsächliche Lösung für das problem. Ich bin mit Spring 2.5, Hibernate 3, Netbeans und Tomcat.

Meine Anwendung ist wie folgt:

servlet.xml

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="interceptors">
            <list>
                <ref bean="openSessionInViewInterceptor" />
            </list>
        </property>
        <property name="mappings">
            <props>
                <prop key="/index.htm">indexController</prop>
            </props>
        </property>
 </bean>
 <bean id ="openSessionInViewInterceptor" name="openSessionInViewInterceptor"
    class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

applicationContext.xml

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref local="dataSource"/>
        </property>
        <property name="mappingResources">
            <list>
                <value>TasquesDAOHibernate/Model/Tasca.hbm.xml</value>
                <value>TasquesDAOHibernate/Model/TipusTasca.hbm.xml</value>
                <value>TasquesDAOHibernate/Model/Prioritat.hbm.xml</value>
                <value>TasquesDAOHibernate/Model/Persona.hbm.xml</value>
                <value>TasquesDAOHibernate/Model/EstatTasca.hbm.xml</value>
                <value>TasquesDAOHibernate/Model/Usuari.hbm.xml</value>
                <value>TasquesDAOHibernate/Model/LogActivitat.hbm.xml</value>
                <value>TasquesDAOHibernate/Model/ObjecteSIPANUsuari.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.jdbc.batch_size">0</prop>
            </props>
        </property>
    </bean>


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

    <bean id="tasquesDAO" class="TasquesDAOHibernate.TasquesDAOHibernate">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>

<bean id="tasquesService" name="tasquesService" class="Tasques_www.service.TasquesService" >
        <property name="tasquesDAO">
            <ref local="tasquesDAO"/>
        </property>
        <property name="transactionManager" ref="transactionManager"/>
    </bean>

TasquesService.java

public List<Tasca> getTasques() {
        List<Tasca> tasques = (List)this.transactionTemplate.execute(new           TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                Object tasques = tasquesDAO.getTasques();
                return tasques;
            }
        });
        return tasques;
    }

TasquesDAOHibernate.java

public List<Tasca> getTasques() {
        Session session = this.sessionFactory.getCurrentSession();
        try{
            Query query = session.createQuery("SELECT element FROM Tasca AS element");
            List result = query.list();
            return result;
        }catch(HibernateException ex){
            return null;
        }
    }

Ich denke, das sind die wichtigen Dateien. Ich habe versucht, viele Dinge und ich bin immer LazyInitializationException oder

org.hibernate.HibernateException: Keine Hibernate-Session gebunden, Faden, und die Konfiguration nicht erlaubt die Erstellung von nicht-transaktionalen hier
...

Ich weiß nicht, welches das schlechteste ist.

Vielen Dank im Voraus!

  • Es hilfreich sein, zu sehen, die bean-definition und Quelle für indexController auch
InformationsquelleAutor | 2009-01-13
Schreibe einen Kommentar