0

This is my problem: I started testing AppFuse in order to understand if it fits or not my needs.

So I start creating a project (AppFuse not the Light version, not the multi module project).

Then I followed the step from Persistance chapter (using Hibernate), creating my beans, daos and manager.

First try: as suggested in the guide I simply configured dao and manager using the AppFuse helper classes (GenericDaoHibernate and GenericManager). Everything works fine.

Second try: I need to create a custom Dao and a custom Manager to deal with my specific business rules ... again following the tutorial ... now I have this problem that is making me crazy:

> 2013-06-24
> 21:42:52.512:WARN:oejs.ServletHandler:/certificati/fornitore
> org.hibernate.HibernateException: No Session found for current thread
>   at
> org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
>   at
> org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:978)
>   at
> org.appfuse.dao.hibernate.GenericDaoHibernate.getSession(GenericDaoHibernate.java:86)
>   at
> org.appfuse.dao.hibernate.GenericDaoHibernate.getAll(GenericDaoHibernate.java:104)
>   at
> org.appfuse.service.impl.GenericManagerImpl.getAll(GenericManagerImpl.java:71)
>   at
> com.alessandrodonato.webapp.controller.FornitoreController.handleRequest(FornitoreController.java:57)

Why ?

I put all the classes (controllers, dao, beans, managers) under the same package .webapp (.webapp.controller, *.webapp.dao, *.webapp.dao.impl, ecc)

my applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
                                                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                                    http://www.springframework.org/schema/context 
                                                    http://www.springframework.org/schema/context/spring-context.xsd
                                                    http://www.springframework.org/schema/tx
                                http://www.springframework.org/schema/tx/spring-tx.xsd"
           default-lazy-init="true">

        <!-- Activates scanning of @Autowired -->
        <context:annotation-config/>

        <!-- Activates scanning of @Repository and @Service -->
        <context:component-scan base-package="com.alessandrodonato"/>

        <!-- Add new DAOs here -->      <!-- <bean id="fornitoreDao" class="org.appfuse.dao.hibernate.GenericDaoHibernate">
            <constructor-arg value="com.alessandrodonato.webapp.model.Fornitore"/> 
        </bean> -->

        <tx:annotation-driven/>

        <!-- Add new Managers here -->      <bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
                <property name = "sessionFactory" ref = "sessionFactory" /> 
     </bean>    
  </beans>

my dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
       default-lazy-init="true">

    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="org.springframework.dao.DataAccessException">
                    dataAccessFailure
                </prop>
            </props>
        </property>
    </bean>

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="2097152"/>
    </bean>

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="ApplicationResources"/>
        <property name="useCodeAsDefaultMessage" value="true"/>
    </bean> 

    <context:component-scan base-package="com.alessandrodonato.webapp"/>

    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven/>

    <!-- Convenient way to map URLs to JSPs w/o having a Controller -->
    <mvc:view-controller path="/admin/activeUsers" view-name="admin/activeUsers"/>
    <mvc:view-controller path="/mainMenu" view-name="mainMenu"/>

    <!-- View Resolver for JSPs -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="requestContextAttribute" value="rc"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- Add additional controller beans here -->

</beans>

My headache is growing up ...

AlexD
  • 81
  • 2
  • 5
  • What does your FornitoreController look like? In other words, how are you injecting the GenericManager? – Matt Raible Jun 24 '13 at 22:33
  • Hi Matt, here my controller https://code.google.com/p/certificati/source/browse/trunk/src/main/java/com/alessandrodonato/webapp/controller/FornitoreController.java – AlexD Jun 25 '13 at 07:42
  • If you use Autowired instead of Resource, does it work? – Matt Raible Jun 27 '13 at 16:56
  • As you can see in the controller, I've used Autowired before Resource. But it doesn't work. – AlexD Jun 28 '13 at 11:50
  • you could try and use the generator of appfuse. (set in the pom file amp.genericCore to false although i get a wiring problem now :( – tibi Aug 21 '13 at 19:51
  • my wiring problem was there because i had an old bean defenition in my xml files :( – tibi Aug 21 '13 at 20:12
  • ah now i get the same: Data Access Failure No Session found for current thread; nested exception is org.hibernate.HibernateException: No Session found for current thread hope i can figure this out .... – tibi Aug 21 '13 at 20:19
  • mmm my problem went away while solving an other probleme (deserializaion because i did not had my model have an @manyToOne) sory i can;t help out – tibi Aug 21 '13 at 21:03

1 Answers1

0

This may have been asked more than a year ago but I hope I could help someone.

I have had similar issue when starting out with appfuse framework. It turns out that I keep forgetting to add single argument constructor in my custom manager implementation. I think, most important part is in passing the autowired dao instance up to parent classes.

Expected custom manager implementation example:

@Service("customManager")
public class CustomManagerImpl extends GenericManagerImpl<User, Long> implements CustomManager {
    private UserDao userDao;
    
    @Autowired
    public CustomManagerImpl(UserDao userDao){
        super(userDao);
        this.userDao = userDao;
    }
}

Hope that helps.