Note that there are some explanatory texts on larger screens.

plurals
  1. POi can`t update my object
    primarykey
    data
    text
    <p>I`m building a spring web application with hibernate. I do not know why but I can not update my object. Below my configuration</p> <p> </p> <pre><code>&lt;bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource" ref="luxpolDataSource" /&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;com.fixus.luxpol.bean.House&lt;/value&gt; &lt;value&gt;com.fixus.luxpol.bean.Photo&lt;/value&gt; &lt;value&gt;com.fixus.luxpol.bean.Service&lt;/value&gt; &lt;value&gt;com.fixus.luxpol.bean.User&lt;/value&gt; &lt;value&gt;com.fixus.luxpol.bean.AccountRole&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.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;mvc:annotation-driven /&gt; &lt;context:component-scan base-package="com.fixus.luxpol" /&gt; &lt;context:component-scan base-package="com.fixus.luxpol.bean" /&gt; </code></pre> <p>So this is my config. When I want to update an object i get this</p> <pre><code>ERROR: org.hibernate.jdbc.AbstractBatcher - Exception executing batch: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85) at ... ERROR: org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70) at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)... </code></pre> <p>I update with hibernate template using update(Object obj) method </p> <p>---- UPDATE</p> <p>I have checked something with my problem. I have changed method from update to saveOrUpdate and it always creates new record in db. I should say that I am sending this object via form. I mean that I have a form with object properties and I am sending it via POST to method where I invoke update (saveOrUpdate) method.</p> <pre><code>@RequestMapping(value = "/admin/house/update", method = RequestMethod.POST) public String updateHouse(House house, Model model) { model.addAttribute("step", 3); this.houseDao.update(house); logger.info("test: " + house.getTitle()); return "houseAdmin"; } </code></pre> <p>I am getting the title in logger so the object is passed. Should I use controller of House object to create instance of this ?</p> <h2>ANSWER</h2> <p>Ok problem was solved. I`m so dumb sometimes. I didn't pass the id via form so the update method couldn't work. Sorry for your time</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