Announcement Announcement Module
Collapse
No announcement yet.
Frustration with JBoss, Hibernate, Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Frustration with JBoss, Hibernate, Spring

    I can't seem to figure out an issue I am having getting read-write access with spring, hibernate and Jboss 4.0.3SP1

    Here is the error I am getting when I try to make an query, or insert I get this error:

    Code:
    20:54:28,078 ERROR [UserFormController] NPE: null
    20:54:28,078 INFO  [STDOUT] java.lang.NullPointerException
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:565)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:507)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.PreparedStatement.toString(PreparedStatement.java:3290)
    20:54:28,078 INFO  [STDOUT]     at java.lang.String.valueOf(String.java:2131)
    20:54:28,078 INFO  [STDOUT]     at java.lang.StringBuffer.append(StringBuffer.java:370)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.printParameters(Tracer.aj:240)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.printEntering(Tracer.aj:167)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.entry(Tracer.aj:126)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.ajc$before$com_mysql_jdbc_trace_Tracer$1$f51c62b8(Tracer.aj:45)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.Connection.registerStatement(Connection.java)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.Statement.<init>(Statement.java:190)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:432)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.ServerPreparedStatement.asSql(ServerPreparedStatement.java:343)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:507)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.ServerPreparedStatement.toString(ServerPreparedStatement.java:2306)
    20:54:28,078 INFO  [STDOUT]     at java.lang.String.valueOf(String.java:2131)
    20:54:28,078 INFO  [STDOUT]     at java.lang.StringBuffer.append(StringBuffer.java:370)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.printParameters(Tracer.aj:240)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.printEntering(Tracer.aj:167)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.entry(Tracer.aj:126)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.trace.Tracer.ajc$before$com_mysql_jdbc_trace_Tracer$1$f51c62b8(Tracer.aj:45)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.Connection.registerStatement(Connection.java)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.Statement.<init>(Statement.java:190)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:414)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.ServerPreparedStatement.<init>(ServerPreparedStatement.java:280)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4288)
    20:54:28,078 INFO  [STDOUT]     at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4226)
    20:54:28,078 INFO  [STDOUT]     at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:312
    )
    20:54:28,078 INFO  [STDOUT]     at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:172)
    20:54:28,078 INFO  [STDOUT]     at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
    20:54:28,078 INFO  [STDOUT]     at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.loader.Loader.doQuery(Loader.java:390)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
    20:54:28,093 INFO  [STDOUT]     at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
    20:54:28,093 INFO  [STDOUT]     at com.baselogic.yoursos.user.User$$EnhancerByCGLIB$$dcedc856.toString(<generated>)
    20:54:28,093 INFO  [STDOUT]     at com.baselogic.yoursos.user.impl.UserManagerImpl.getUser(UserManagerImpl.java:70)
    20:54:28,093 INFO  [STDOUT]     at com.baselogic.yoursos.user.UserFormController.onSubmit(UserFormController.java:72)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:259)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:717)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:658)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
    20:54:28,093 INFO  [STDOUT]     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:357)
    20:54:28,093 INFO  [STDOUT]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    20:54:28,093 INFO  [STDOUT]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    20:54:28,093 INFO  [STDOUT]     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    20:54:28,093 INFO  [STDOUT]     at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
    20:54:28,093 INFO  [STDOUT]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
    20:54:28,093 INFO  [STDOUT]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    20:54:28,093 INFO  [STDOUT]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    20:54:28,093 INFO  [STDOUT]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    20:54:28,093 INFO  [STDOUT]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
    20:54:28,093 INFO  [STDOUT]     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    20:54:28,093 INFO  [STDOUT]     at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    20:54:28,093 INFO  [STDOUT]     at java.lang.Thread.run(Thread.java:534)
    20:54:28,093 DEBUG [UserFormController] ==================================================================================================
    20:54:28,093 DEBUG [UserFormController] Returned user:
    20:54:28,093 WARN  [UserFormController] returned User is null!
    20:54:28,093 DEBUG [UserFormController] ==================================================================================================

  • #2
    Here is my applicationContext.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
        <!-- Local DataSource that works in any environment -->
        <!-- Note that DriverManagerDataSource does not pool; it is not intended for production -->
        <!--
            <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName"><value>org.gjt.mm.mysql.Driver</value></property>
                <property name="url"><value>jdbc:mysql://localhost:3306/yoursos</value></property>
                <property name="username"><value>xxx</value></property>
                <property name="password"><value>xxx</value></property>
            </bean>
        -->
    
        <!-- Datasource for YourSOS Database -->
        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName">
                <value>java:jndi/yoursos</value>
            </property>
            <property name="resourceRef">
                <value>false</value>
            </property>
        </bean>
    
    
        <bean name="openSessionInViewInterceptor"
              class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
            <!-- I don't like this. I would prefer the view interceptor to be readonly,
                but the hibernate interceptor I just added is not resetting the flush mode back when
                both OSIVInterceptor and HInterceptor are being used. -->
            <property name="flushMode">
                <value>3</value>
            </property>
            <!-- org.springframework.orm.hibernate3.HibernateInterceptor.FLUSH_EAGER, but how to do it? -->
        </bean>
    
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource">
                <ref local="dataSource"/>
            </property>
            <property name="mappingResources">
                <list>
                    <value>com/baselogic/yoursos/user/User.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <!--<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
                    <prop key="hibernate.cache.use_query_cache">false</prop>-->
                    <!--<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>-->
                </props>
            </property>
            <property name="eventListeners">
                <map>
                    <entry key="merge">
                        <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
                    </entry>
                </map>
            </property>
        </bean>
    
    
        <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
        </bean>
    
        <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
    
        <!--<bean id="transactionManager"
              class="org.springframework.transaction.jta.JtaTransactionManager">
            <property name="userTransactionName">
                <value>UserTransaction</value>
            </property>
            <property name="transactionManagerName">
                <value>java:/TransactionManager</value>
            </property>
        </bean>-->
    
        <!--
    	- Transactional proxy for Consumer's central data access object.
    	-
    	- Defines specific transaction attributes with "readOnly" markers,
    	- which is an optimization that is particularly valuable with Hibernate
    	- (to suppress unnecessary flush attempts for read-only operations).
        -->
        <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
              abstract="true">
            <property name="transactionManager">
                <ref local="transactionManager"/>
            </property>
            <property name="target">
                <ref local="userManager"/>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="store*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
    
    
        <!--===== BUSINESS OBJECT DEFINITIONS ===========================================================================-->
    
        <bean id="userTransactionProxy" parent="baseTransactionProxy">
            <property name="target">
                <ref local="userManager"/>
            </property>
        </bean>
    
        <!--
            <bean id="userManager" class="org.springframework.aop.framework.ProxyFactoryBean">
                 <property name="target"><ref bean="userManagerTarget"/></property>
                 <property name="proxyInterfaces">
                   <value>com.baselogic.yoursos.user.UserManager</value>
                 </property>
                 <property name="interceptorNames">
                   <list>
                      <value>hibernateInterceptor</value>
                   </list>
                 </property>
             </bean>
        -->
    
    
        <bean id="userManager" class="com.baselogic.yoursos.user.impl.UserManagerImpl">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
        </bean>
    
        <!--
            <bean id="userManager" parent="baseTransactionProxy">
                <property name="target">
                    <bean class="com.baselogic.yoursos.user.impl.UserManagerImpl" >
                        <property name="sessionFactory">
                            <ref local="baseSessionFactory"/>
                        </property>
                    </bean>
                </property>
            </bean>
        -->
    
    
        <!--=== WEB MAPPINGS =========================================================================================== -->
        <!-- MultipartResolver for parsing file uploads, implementation for Commons FileUpload -->
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize">
                <value>4000000</value>
            </property>
        </bean>
    
        <!-- MultipartResolver for parsing file uploads, implementation for Jason Hunter's COS -->
        <!-- Uncomment this and comment out the above to switch to COS as multipart parsing strategy -->
        <!--
         <bean id="multipartResolver" class="org.springframework.web.multipart.cos.CosMultipartResolver"/>
         -->
    
    
        <bean id="generalExceptionMapping" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            <property name="exceptionMappings">
                <!-- each exception can have a corresponding view name -->
                <props>
                    <prop key="org.springframework.dao.DataAccessException">common/technicaldifficulty</prop>
                    <prop key="org.springframework.transaction.TransactionException">common/technicaldifficulty</prop>
                    <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">
                        common/technicaldifficulty</prop>
                </props>
            </property>
            <property name="defaultErrorView">
                <value>common/technicaldifficulty</value>
            </property>
            <property name="order">
                <value>1</value>
            </property>
        </bean>
    
        <bean id="messageSource"
              class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename">
                <value>messages</value>
            </property>
        </bean>
    
        <!-- Simple ViewResolver for JSP, prepending "/WEB-INF/views" and appending ".jsp" to logical view names -->
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass">
                <value>org.springframework.web.servlet.view.JstlView</value>
            </property>
            <property name="prefix">
                <value>/WEB-INF/views/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>
    
    
    </beans>

    Comment


    • #3
      Here is my user-servlet.xml:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
      
      <beans>
      
      
          <!-- A very basic URL mapping, all requests are mapped to the user controller -->
          <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="/register">userFormController</prop>
                      <prop key="/editUser">userFormController</prop>
                  </props>
              </property>
          </bean>
      
          <!--
            The controller class, this is where the magic happens.  The resolver maps the request URIs
            to method names, and the 'service' class is the business delegate that actually does the
            offer logic.  The offer service is setup in the 'applicationContext' config file.
          -->
          <bean id="userValidator" class="com.baselogic.yoursos.user.UserValidator"/>
      
          <bean id="userFormController" autowire="byName" class="com.baselogic.yoursos.user.UserFormController">
              <property name="sessionForm"><value>true</value></property>
              <property name="commandName"><value>userSearchParameters</value></property>
              <property name="commandClass"><value>com.baselogic.yoursos.user.User</value></property>
              <!--<property name="validator"><ref bean="userValidator"/></property>-->
              <property name="formView"><value>registration/index</value></property>
              <property name="successView"><value>registration/success</value></property>
              <property name="manager"><ref bean="userManager"/></property>
          </bean>
      
          <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
              <property name="basename"><value>messages</value></property>
          </bean>
      
          <!--===== BUSINESS OBJECT DEFINITIONS ===========================================================================-->
      
      
          <!--===== MISC OBJECT DEFINITIONS ===============================================================================-->
          <!-- Since this page will only be included by others, uses the error page
               that's set up for includes.  (Doesn't have header, footer, etc.) -->
          <bean id="generalExceptionMapping" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
              <property name="defaultErrorView">
                  <value>common/technicaldifficulty</value>
              </property>
          </bean>
      </beans>
      here is my web.xml:
      Code:
          <listener>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          <servlet>
              <servlet-name>user</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <load-on-startup>2</load-on-startup>
          </servlet>
      
      
          <servlet-mapping>
              <servlet-name>user</servlet-name>
              <url-pattern>/user/*</url-pattern>
          </servlet-mapping>
      I have spent the last 2 days reading this forum, jboss, and hibernate, and no luck thusfar. I would greatly appreciate some help with this...

      Comment


      • #4
        Possible lazy problem

        Hi,

        I see in your call stack that in getUser() the toString method is called and therefor a lazy fetching is activated.
        I think you should be careful with printing association in toString-method. I'd done by myself and I got many problems.

        regards,
        Juergen

        Comment


        • #5
          I am only printing so that I can figure out why I am getting a NPE after the fetch, or a save. I have tried both.
          It seems that I get to my Hibernate Template DAO, but still throw an NPE. Any idea why?

          Originally posted by jmelzer
          Hi,

          I see in your call stack that in getUser() the toString method is called and therefor a lazy fetching is activated.
          I think you should be careful with printing association in toString-method. I'd done by myself and I got many problems.

          regards,
          Juergen

          Comment

          Working...
          X