Note that there are some explanatory texts on larger screens.

plurals
  1. POSet flush Mode to AUTO in Spring 3.0 failure
    primarykey
    data
    text
    <p>I am using Spring 3.0 rest, hibernate 3 and Android 4. When trying to add an user in my db table things stop working. Object set on post, using Android and Spring 3.1 is always null. This is on the server side, in the Spring Controller:</p> <pre><code>@Transactional(readOnly = false) @RequestMapping(value = "/user/add/", method = RequestMethod.POST, headers = "Accept=application/json,text/html,application/xhtml+xml,application/xml", consumes ="{MediaType.APPLICATION_JSON_VALUE}", produces = "{MediaType.APPLICATION_JSON_VALUE}") public @ResponseBody User registerUser(@ModelAttribute("user") User user, HttpServletResponse response) throws IOException { return userService.saveUser(user); } </code></pre> <p>Here user is Always null and inserts in db of course..null values.</p> <p>From Android this is how i send my object:</p> <pre><code>try { RestTemplate restTemplate = new RestTemplate(); GenericEntityWithJson getEntityHeader = new GenericEntityWithJson(); HttpEntity&lt;Taxi&gt; entityHeader = getEntityHeader .getHttpEntityWithJsonHeaders(user); response = restTemplate.postForObject(url, entityHeader, User.class); } catch (Exception e) { System.out.println("register error: " + e.getMessage()); } </code></pre> <p>My persistence.xml code:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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" 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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt; &lt;!-- Load in application properties reference --&gt; &lt;bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="location" value="classpath:be/taximobile/rest/resources/database.properties"/&gt; &lt;/bean&gt; &lt;bean id="mysqlDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${db.driverClassName}" /&gt; &lt;property name="url" value="${db.url}" /&gt; &lt;property name="username" value="${db.username}" /&gt; &lt;property name="password" value="${db.password}" /&gt; &lt;/bean&gt; &lt;!-- Hibernate SessionFactory --&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref local="mysqlDataSource" /&gt; &lt;/property&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;be.taximobile.rest.bean.Client&lt;/value&gt; &lt;value&gt;be.taximobile.rest.bean.Taxi&lt;/value&gt; &lt;value&gt;be.taximobile.rest.bean.ClientCommand&lt;/value&gt; &lt;value&gt;be.taximobile.rest.bean.TaxiFeatures&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt; org.hibernate.dialect.MySQLDialect &lt;/prop&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt; &lt;prop key="lazy"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.generate_statistics"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.use_sql_comments"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- Configure Transaction manager for a single Hibernate SessionFactory(because we are using one database source only, and so a single Session Factory) --&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;property name="rollbackOnCommitFailure" value="true" /&gt; &lt;/bean&gt; &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;/bean&gt; &lt;!-- define DAO and Service beans --&gt; &lt;bean id="clientDao" class="be.taximobile.rest.persistence.ClientDAOImpl"&gt; &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt; &lt;/bean&gt; &lt;bean id="featureDao" class="be.taximobile.rest.persistence.FeatureDAOImpl"&gt; &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt; &lt;/bean&gt; &lt;bean id="orderDao" class="be.taximobile.rest.persistence.OrderDAOImpl"&gt; &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt; &lt;/bean&gt; &lt;bean id="taxiDao" class="be.taximobile.rest.persistence.TaxiDAOImpl"&gt; &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt; &lt;/bean&gt; &lt;bean id="orderService" class="be.taximobile.rest.services.OrderServiceImpl" &gt; &lt;property name="orderDao"&gt; &lt;ref bean="orderDao" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="taxiService" class="be.taximobile.rest.services.TaxiServiceImpl" &gt; &lt;property name="taxiDao"&gt; &lt;ref bean="taxiDao" /&gt; &lt;/property&gt; &lt;property name="featureDao"&gt; &lt;ref bean="featureDao" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="featureService" class="be.taximobile.rest.services.FeatureServiceImpl" &gt; &lt;property name="featureDao"&gt; &lt;ref bean="featureDao" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="clientService" class="be.taximobile.rest.services.ClientServiceImpl" &gt; &lt;property name="clientDao"&gt; &lt;ref bean="clientDao" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- end &lt;bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;property name="flushModeName" value="FLUSH_AUTO" /&gt; &lt;/bean&gt; --&gt; &lt;/beans&gt; </code></pre> <p>Servlet.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt; &lt;!-- To enable autodetection of such annotated controllers, you add component scanning to your configuration. --&gt; &lt;context:component-scan base-package="be.taximobile.rest.controller" /&gt; &lt;!-- hibernate configuration &lt;import resource="TaxiMobileBackend-persistence.xml" /&gt;--&gt; &lt;!-- To enable @RequestMapping process on type level and method level --&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="messageConverters"&gt; &lt;list&gt; &lt;ref bean="jsonConverter" /&gt; &lt;ref bean="marshallingConverter" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt; &lt;property name="supportedMediaTypes" value="application/json" /&gt; &lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt; &lt;bean id="marshallingConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt; &lt;constructor-arg ref="jaxbMarshaller" /&gt; &lt;property name="supportedMediaTypes" value="application/xml"/&gt; &lt;/bean&gt; &lt;!-- JAXB2 marshaller. Automagically turns beans into xml --&gt; &lt;bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt; &lt;property name="classesToBeBound"&gt; &lt;list&gt; &lt;value&gt;be.taximobile.rest.bean.Client&lt;/value&gt; &lt;value&gt;be.taximobile.rest.bean.Taxi&lt;/value&gt; &lt;value&gt;be.taximobile.rest.bean.ClientCommand&lt;/value&gt; &lt;value&gt;be.taximobile.rest.bean.TaxiFeatures&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- Mape views --&gt; &lt;bean id="jsonview" class="org.springframework.web.servlet.view.xml.MarshallingView"&gt; &lt;constructor-arg ref="jaxbMarshaller" /&gt; &lt;/bean&gt; &lt;bean id="taxis" class="org.springframework.web.servlet.view.xml.MarshallingView"&gt; &lt;constructor-arg ref="jaxbMarshaller" /&gt; &lt;/bean&gt; &lt;bean id="orders" class="org.springframework.web.servlet.view.xml.MarshallingView"&gt; &lt;constructor-arg ref="jaxbMarshaller" /&gt; &lt;/bean&gt; &lt;bean id="taxi" class="org.springframework.web.servlet.view.xml.MarshallingView"&gt; &lt;constructor-arg ref="jaxbMarshaller" /&gt; &lt;/bean&gt; &lt;bean id="client" class="org.springframework.web.servlet.view.xml.MarshallingView"&gt; &lt;constructor-arg ref="jaxbMarshaller" /&gt; &lt;/bean&gt; &lt;bean id="order" class="org.springframework.web.servlet.view.xml.MarshallingView"&gt; &lt;constructor-arg ref="jaxbMarshaller" /&gt; &lt;/bean&gt; &lt;!-- end --&gt; &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"&gt; &lt;property name="contentType" value="text/plain"/&gt; &lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt; &lt;property name="mediaTypes"&gt; &lt;map&gt; &lt;entry key="json" value="application/json"/&gt; &lt;!-- &lt;entry key="xml" value="application/xml"/&gt; &lt;entry key="html" value="text/html"/&gt; --&gt; &lt;/map&gt; &lt;/property&gt; &lt;property name="viewResolvers"&gt; &lt;list&gt; &lt;bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt; &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt; &lt;property name="prefix" value="/WEB-INF/jsp/"/&gt; &lt;property name="suffix" value=".jsp"/&gt; &lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="messageConverters"&gt; &lt;list&gt; &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- Controllers --&gt; &lt;bean id="taxiController" class="be.taximobile.rest.controller.TaxiController"&gt; &lt;property name="taxiService" ref="taxiService" /&gt; &lt;/bean&gt; &lt;bean id="clientController" class="be.taximobile.rest.controller.ClientController"&gt; &lt;property name="clientService" ref="clientService" /&gt; &lt;/bean&gt; &lt;bean id="orderController" class="be.taximobile.rest.controller.OrderController"&gt; &lt;property name="orderService" ref="orderService" /&gt; &lt;property name="taxiService" ref="taxiService" /&gt; &lt;/bean&gt; &lt;bean id="featuresController" class="be.taximobile.rest.controller.TaxiFeaturesController"&gt; &lt;property name="featureService" ref="featureService" /&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>WEb.xml file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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_1.xsd" metadata-complete="true"&gt; &lt;display-name&gt;be.taximobile.rest&lt;/display-name&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;!-- The context params that read by ContextLoaderListener --&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; /WEB-INF/TaxiMobileBackend-context.xml &lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- This listener will load other application context file in addition to springweb-servlet.xml --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;TaxiMobileBackend&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;TaxiMobileBackend&lt;/servlet-name&gt; &lt;url-pattern&gt;/service/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;jsp-config&gt; &lt;taglib&gt; &lt;taglib-uri&gt;http://java.sun.com/jsp/jstl/core&lt;/taglib-uri&gt; &lt;taglib-location&gt;/WEB-INF/tags/c.tld&lt;/taglib-location&gt; &lt;/taglib&gt; &lt;/jsp-config&gt; &lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/log4j.properties&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;filter&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.orm.hibernate3.support.OpenSessionInViewFilter&lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;sessionFactoryBeanName&lt;/param-name&gt; &lt;param-value&gt;sessionFactory&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;/web-app&gt; </code></pre> <p>Here before the post action, my object <code>user</code> has values. i receive no errors on the client side, it goes right to the server one but there it reaches as null. I don't understand this at all, tried using @RequestBody and it doesn't even enter my controller method. Have you encountered this before, any ideas would be great. did anyone had this error before? I really don't know what to try anymore at this moment. Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload