Announcement Announcement Module
Collapse
No announcement yet.
Spring, Jboss AS7, Hibernate 4 - call to persist won't commit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring, Jboss AS7, Hibernate 4 - call to persist won't commit

    Hi guys,

    I have and app with Spring, JBoss AS7 and Hibernate 4. For some reson, everything seem to work fine. I can even query the database. But, when I call persist on my entityManager, nothing happens. It looks like it is not commiting transactions on the database. I've already played around with the @Transactional annotation initially put only on the top of my Service class.
    Please, guys. Any help or suggestion is more then welcome!


    Here go my config files for persistance:


    persistance.xml:

    Code:
    <persistence version="2.0"
    	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="
            http://java.sun.com/xml/ns/persistence
            http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    	<persistence-unit name="ekobinPersistenceUnit">
          <!-- If you are running in a production environment, add a managed 
             data source, this example data source is just for development and testing! -->
          <!-- The datasource is deployed as WEB-INF/spring-quickstart-ds.xml, you
             can find it in the source at src/main/webapp/WEB-INF/spring-quickstart-ds.xml -->
          <jta-data-source>java:jboss/datasources/MysqlDS</jta-data-source>
          <properties>
             <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/ekobin/persistence" />
             <!-- Properties for Hibernate -->
             <property name="hibernate.hbm2ddl.auto" value="create-drop" />
             <property name="hibernate.show_sql" value="true" />
          </properties>
       </persistence-unit>
    </persistence>

    infrastructure.xml

    Code:
    <?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:jee="http://www.springframework.org/schema/jee" 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/tx
    		   http://www.springframework.org/schema/tx/spring-tx.xsd
    		   http://www.springframework.org/schema/jee 
    		   http://www.springframework.org/schema/jee/spring-jee.xsd">
    
        <!-- JDNI name for EntityManagerFactory is defined in src/main/resources/META-INF/persistence.xml -->
        <jee:jndi-lookup jndi-name="java:jboss/ekobin/persistence" id="entityManagerFactory"
            expected-type="javax.persistence.EntityManagerFactory" />
    <!-- 
        <jee:jndi-lookup jndi-name="java:jboss/datasources/MysqlDS" id="dataSource"
            expected-type="javax.sql.DataSource" />
     -->
    
        <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
    
        <tx:jta-transaction-manager />
    
        <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <property name="basenames">
                <list>
                    <value>classpath:messages/pageText</value>
                    <value>classpath:messages/general</value>
                </list>
            </property>
            <property name="defaultEncoding" value="UTF-8"></property>
            <property name="fallbackToSystemLocale" value="false" />
            <property name="cacheSeconds" value="3" />
            <property name="fileEncodings" value="UTF-8" />
        </bean>
    
        <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
            <property name="defaultLocale" value="pt_BR"></property>
        </bean>
    
    </beans>
    applicationContext.xml

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee" 
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:security="http://www.springframework.org/schema/security"
        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-3.0.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    		http://www.springframework.org/schema/security
           	http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">    
    
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.user" />
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.device" />
    	<context:component-scan base-package="br.com.ekoimpacto.ekobin.material" />
    	<context:component-scan base-package="br.com.ekoimpacto.ekobin.general" />
    
        <tx:annotation-driven />
    
    </beans>

  • #2
    How are you loading your configuration (post your web.xml if you have that). Make sure you are scanning only once for components not multiple times (also note that you can put a , seperated list in the base-package attribute, saves you a couple of elements).

    Comment


    • #3
      Hi Marten,

      Thank you for the advice about the base-package, didn't know that.

      Here it is my web.xml:
      Code:
      <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
               http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
          metadata-complete="true">
      
          <display-name>Ekobin</display-name>
          <context-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>classpath:/META-INF/spring/applicationContext.xml,
      				classpath:/META-INF/spring/infrastructure.xml</param-value>
          </context-param>
      
          <listener>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
      
          <filter>
              <filter-name>openSessionInViewFilter</filter-name>
              <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
              <init-param>
                  <param-name>entityManagerFactoryBeanName</param-name>
                  <param-value>entityManagerFactory</param-value>
              </init-param>
          </filter>
      
          <filter-mapping>
              <filter-name>openSessionInViewFilter</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
      
          <servlet>
              <servlet-name>ekobin</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <init-param>
                  <param-name>contextConfigLocation</param-name>
                  <param-value>/WEB-INF/jboss-as-spring-mvc-context.xml</param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>
          </servlet>
      
          <servlet-mapping>
              <servlet-name>ekobin</servlet-name>
              <url-pattern>/</url-pattern>
          </servlet-mapping>
          
      </web-app>
      Last edited by Luciane Araujo; Feb 5th, 2013, 03:40 AM.

      Comment


      • #4
        Please use [ code][/code ] tags when posting code that way it remains readable...

        Canyou also post your mvc-context.xml....

        Comment


        • #5
          Sorry... In the hurry I forgot the code tag.
          Thank you for the attention and help.
          Here it goes the mvc-context:


          Code:
          <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">
          
              <context:component-scan base-package="br.com.ekoimpacto.ekobin.general" />
              
              <context:component-scan base-package="br.com.ekoimpacto.ekobin.device" />
              
              <context:component-scan base-package="br.com.ekoimpacto.ekobin.user" />
              
              <context:component-scan base-package="br.com.ekoimpacto.ekobin.material" />
          
              <mvc:annotation-driven />
          
              <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                  <property name="prefix" value="/WEB-INF/views/" />
                  <property name="suffix" value=".jsp" />
              </bean>
          
              <mvc:resources mapping="/static/**" location="/WEB-INF/static/" />
          
              <mvc:default-servlet-handler />
          
          </beans>

          Comment


          • #6
            And there is your problem... You are duplicating your bean instances, both the ContextLoaderListener as well as the DispatcherServlet instantiate the same beans, the last one without transactions and those are the beans being used. This has been explained on the forum before so you might want to do a search...

            But in short, your ContextLoaderListener should scan for everything BUT (@)Controllers and your DispatcherServlet should only scan for (@)Controllers.

            Comment


            • #7
              Exactly! It is really nice when you know what to look for. 2 days wasted, affff...

              Anyway, thank you very much!

              Comment

              Working...
              X