-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: StaleObjectStateException on flush
PostPosted: Thu Dec 21, 2006 1:47 am 
Newbie

Joined: Wed Dec 20, 2006 10:52 pm
Posts: 7
I have the following code :

Code:
Transaction transaction = null;
try {
  SupplierDao supplierDao = SuppliersEMDaoFactory.getInstance().getSupplierDao();
          
  Session hibernateSession = ServiceLocator.getCurrentSession();
  transaction = hibernateSession.beginTransaction();

  Supplier supplier = new Supplier();
  supplierDao.generateKey(supplier);
                     
  supplier.setName("Name1");
          
  hibernateSession.saveOrUpdate(supplier);
          
  supplier.setName("Name2"); // bad code

  hibernateSession.flush();
  transaction.commit();
         
}
catch (Exception e) {
  e.printStackTrace();
  transaction.rollback();
}


When I execute it, the following exception is thrown by the flush() call :

Code:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [net.cpaerp.suppliers.application.business.entity.Supplier#a37a9e6fffffff80006060325ce866f9]
   at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1714)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at net.cpaerp.suppliers.application.presentation.TestExecute.execute(TestExecute.java:74)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
...


(the code is in the execute method of the TestExecute struts action class)

If i remove the line
Code:
supplier.setName("Name2"); // bad code
I have no error.

I'm using the last release of Hibernate 3.2.1 GA

This are my config files :

Code:
<hibernate-configuration>

    <session-factory>

        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
 
        <property name="connection.datasource">java:/DefaultDS</property>

        <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

        <property name="current_session_context_class">managed</property>

        <property name="hibernate.show_sql">true</property>

        <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>

        <mapping resource="net/cpaerp/suppliers/application/business/entity/Contact.hbm.xml"/>
        <mapping resource="net/cpaerp/suppliers/application/business/entity/Supplier.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

Supplier.hbm.xml :
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping >

    <class
        name="net.cpaerp.suppliers.application.business.entity.Supplier"
        table="Supplier"
        optimistic-lock="version"
        mutable="true"
        >

        <id
            name="id"
            column="uniqueId"
            type="string">
            <generator class="assigned"/>
        </id>

        <timestamp
            name="timestamp"
            column="timestamp_column"
        />

        <property name="name" type="string">
            <column name="name"/>
        </property>

        <property name="telephone" type="string">
            <column name="telephone"/>
        </property>

        <bag
            name="contact"
            inverse="true"
            cascade="save-update,merge"
            >
            <key>
                <column name="SupplierUniqueId"/>
            </key>
            <one-to-many
                class="net.cpaerp.suppliers.application.business.entity.Contact"
            />
        </bag>

    </class>

    <query name="Supplier_findAll">
        <![CDATA[
        select new list(supplier)
        FROM Supplier AS supplier
        ]]>
    </query>

    <query name="Supplier_findByContact">
        <![CDATA[
        select new list(supplier)
        FROM Supplier AS supplier
            LEFT JOIN supplier.contact AS contact
            WHERE contact.id = :contactId
        ]]>
    </query>

    <query name="Supplier_findByName">
        <![CDATA[
        select new list(supplier)
        FROM Supplier AS supplier
            WHERE supplier.name LIKE :name
        ]]>
    </query>

</hibernate-mapping>


Do anybody have an idea??

Why can't we modify a new object after calling the saveOrUpdate (or just save) method on the hibernate session? Is this normal? Is it some kind of locking issue?

I use the timestamp versionning feature. After calling the saveOrUpdate method with my object, the value of the timestamp column is initialized to now.

Two lines are logged in the org.hibernate.SQL logger :
Code:
insert into Supplier (timestamp_column, name, telephone, uniqueId) values (?, ?, ?, ?)
update Supplier set timestamp_column=?, name=?, telephone=? where uniqueId=? and timestamp_column=?


Obviously, the insertion is done in two database access. One for inserting, and one for some update. I set autocommit to true to see what was inserted on the insert call, and the following fields were filled :

- the id column with the key generated by my dao
- the timestamp column
- the name column with the value "name1"

And the second update update nothing, the exception is thrown and the transaction rollbacked.

I'm confuse... how can I cancel the first insert and replace the update by an insert with the same values?

Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 2:58 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Try and add org.hibernate.type in the log4j file, or at least to display the debug infos of this package. This way you'll see what Hibernate puts inside the ? parameters.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 11:05 am 
Newbie

Joined: Wed Dec 20, 2006 10:52 pm
Posts: 7
I'll send you what I log :

It's every error on my server plus everything in org.hibernate. I have no logger called org.hibernate.type

important : start reading by the bottom!

Code:
Debug   446.625   false   org.hibernate.jdbc.ConnectionManager   releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
Debug   446.625   false   org.hibernate.jdbc.ConnectionManager   aggressively releasing JDBC connection
Error   446.625   true   org.hibernate.transaction.JDBCTransaction   JDBC rollback failed
Debug   446.625   false   org.hibernate.transaction.JDBCTransaction   re-enabling autocommit
Debug   446.609   false   org.hibernate.transaction.JDBCTransaction   rollback
Error   446.594   false   STDERR   org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [net.cpaerp.suppliers.application.business.entity.Supplier#a57f83a1ffffff8001a04d30da1d4eab]
   at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1714)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at net.cpaerp.suppliers.application.presentation.TestExecute.execute(TestExecute.java:75)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at net.cpaerp.suppliers.application.presentation.filters.SetCharacterEncodingFilterSuppliersWeb.doFilter(SetCharacterEncodingFilterSuppliersWeb.java:140)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at net.cpaerp.suppliers.application.presentation.filters.SuppliersWebServletFilter.doFilter(SuppliersWebServletFilter.java:54)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
   at java.lang.Thread.run(Thread.java:595)
Error   445.984   true   org.hibernate.event.def.AbstractFlushingEventListener   Could not synchronize database state with session
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
Debug   445.969   false   org.hibernate.SQL   update Supplier set timestamp_column=?, name=?, telephone=? where uniqueId=? and timestamp_column=?
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
Debug   445.969   false   org.hibernate.jdbc.Expectations   success of batch update unknown: 0
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   Executing batch size: 1
Debug   445.953   false   org.hibernate.SQL   insert into Supplier (timestamp_column, name, telephone, uniqueId) values (?, ?, ?, ?)
Debug   445.938   false   org.hibernate.jdbc.AbstractBatcher   about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
Debug   445.938   false   org.hibernate.pretty.Printer   net.cpaerp.suppliers.application.business.entity.Supplier{contact=[], telephone=null, timestamp=2006-12-21 09:58:13, name=Name2, id=a584fe37ffffff8001a04d307597fe2c}
Debug   445.938   false   org.hibernate.pretty.Printer   net.cpaerp.suppliers.application.business.entity.Supplier{contact=[], telephone=null, timestamp=2006-12-21 09:52:14, name=Name2, id=a57f83a1ffffff8001a04d30da1d4eab}
Debug   445.938   false   org.hibernate.pretty.Printer   listing entities:
Debug   445.938   false   org.hibernate.event.def.AbstractFlushingEventListener   Flushed: 3 (re)creations, 0 updates, 0 removals to 2 collections
Debug   445.938   false   org.hibernate.event.def.AbstractFlushingEventListener   Flushed: 1 insertions, 3 updates, 0 deletions to 2 objects
Debug   445.922   false   org.hibernate.engine.Collections   Collection found: [net.cpaerp.suppliers.application.business.entity.Supplier.contact#a584fe37ffffff8001a04d307597fe2c], was: [<unreferenced>] (initialized)
Debug   445.906   false   org.hibernate.engine.Collections   Collection found: [net.cpaerp.suppliers.application.business.entity.Supplier.contact#a57f83a1ffffff8001a04d30da1d4eab], was: [<unreferenced>] (initialized)
Debug   445.906   false   org.hibernate.event.def.AbstractFlushingEventListener   dirty checking collections
Debug   445.906   false   org.hibernate.event.def.AbstractFlushingEventListener   processing flush-time cascades
Debug   445.891   false   org.hibernate.event.def.AbstractSaveEventListener   generated identifier: a584fe37ffffff8001a04d307597fe2c, using strategy: org.hibernate.id.Assigned
Debug   445.813   false   org.hibernate.transaction.JDBCTransaction   disabling autocommit
Debug   445.813   false   org.hibernate.transaction.JDBCTransaction   current autocommit status: true
Debug   445.813   false   org.hibernate.jdbc.ConnectionManager   opening JDBC connection
Debug   445.781   false   org.hibernate.transaction.JDBCTransaction   begin


Anyway that don'T solve my problem who is the fact that it create an insert with the values of my object when I call the saveOrUpdate plus an update with the current values... I don't care about the first values. And worst, it don't works! I have an error...

Thanks for your fast answer. If I can do what you says, it will really helps me.

Emmanuel[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 11:05 am 
Newbie

Joined: Wed Dec 20, 2006 10:52 pm
Posts: 7
I'll send you what I log :

It's every error on my server plus everything in org.hibernate. I have no logger called org.hibernate.type

important : start reading by the bottom!

Code:
Debug   446.625   false   org.hibernate.jdbc.ConnectionManager   releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
Debug   446.625   false   org.hibernate.jdbc.ConnectionManager   aggressively releasing JDBC connection
Error   446.625   true   org.hibernate.transaction.JDBCTransaction   JDBC rollback failed
Debug   446.625   false   org.hibernate.transaction.JDBCTransaction   re-enabling autocommit
Debug   446.609   false   org.hibernate.transaction.JDBCTransaction   rollback
Error   446.594   false   STDERR   org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [net.cpaerp.suppliers.application.business.entity.Supplier#a57f83a1ffffff8001a04d30da1d4eab]
   at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1714)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at net.cpaerp.suppliers.application.presentation.TestExecute.execute(TestExecute.java:75)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at net.cpaerp.suppliers.application.presentation.filters.SetCharacterEncodingFilterSuppliersWeb.doFilter(SetCharacterEncodingFilterSuppliersWeb.java:140)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at net.cpaerp.suppliers.application.presentation.filters.SuppliersWebServletFilter.doFilter(SuppliersWebServletFilter.java:54)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
   at java.lang.Thread.run(Thread.java:595)
Error   445.984   true   org.hibernate.event.def.AbstractFlushingEventListener   Could not synchronize database state with session
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
Debug   445.969   false   org.hibernate.SQL   update Supplier set timestamp_column=?, name=?, telephone=? where uniqueId=? and timestamp_column=?
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
Debug   445.969   false   org.hibernate.jdbc.Expectations   success of batch update unknown: 0
Debug   445.969   false   org.hibernate.jdbc.AbstractBatcher   Executing batch size: 1
Debug   445.953   false   org.hibernate.SQL   insert into Supplier (timestamp_column, name, telephone, uniqueId) values (?, ?, ?, ?)
Debug   445.938   false   org.hibernate.jdbc.AbstractBatcher   about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
Debug   445.938   false   org.hibernate.pretty.Printer   net.cpaerp.suppliers.application.business.entity.Supplier{contact=[], telephone=null, timestamp=2006-12-21 09:58:13, name=Name2, id=a584fe37ffffff8001a04d307597fe2c}
Debug   445.938   false   org.hibernate.pretty.Printer   net.cpaerp.suppliers.application.business.entity.Supplier{contact=[], telephone=null, timestamp=2006-12-21 09:52:14, name=Name2, id=a57f83a1ffffff8001a04d30da1d4eab}
Debug   445.938   false   org.hibernate.pretty.Printer   listing entities:
Debug   445.938   false   org.hibernate.event.def.AbstractFlushingEventListener   Flushed: 3 (re)creations, 0 updates, 0 removals to 2 collections
Debug   445.938   false   org.hibernate.event.def.AbstractFlushingEventListener   Flushed: 1 insertions, 3 updates, 0 deletions to 2 objects
Debug   445.922   false   org.hibernate.engine.Collections   Collection found: [net.cpaerp.suppliers.application.business.entity.Supplier.contact#a584fe37ffffff8001a04d307597fe2c], was: [<unreferenced>] (initialized)
Debug   445.906   false   org.hibernate.engine.Collections   Collection found: [net.cpaerp.suppliers.application.business.entity.Supplier.contact#a57f83a1ffffff8001a04d30da1d4eab], was: [<unreferenced>] (initialized)
Debug   445.906   false   org.hibernate.event.def.AbstractFlushingEventListener   dirty checking collections
Debug   445.906   false   org.hibernate.event.def.AbstractFlushingEventListener   processing flush-time cascades
Debug   445.891   false   org.hibernate.event.def.AbstractSaveEventListener   generated identifier: a584fe37ffffff8001a04d307597fe2c, using strategy: org.hibernate.id.Assigned
Debug   445.813   false   org.hibernate.transaction.JDBCTransaction   disabling autocommit
Debug   445.813   false   org.hibernate.transaction.JDBCTransaction   current autocommit status: true
Debug   445.813   false   org.hibernate.jdbc.ConnectionManager   opening JDBC connection
Debug   445.781   false   org.hibernate.transaction.JDBCTransaction   begin


Anyway that don'T solve my problem who is the fact that it create an insert with the values of my object when I call the saveOrUpdate plus an update with the current values... I don't care about the first values. And worst, it don't works! I have an error...

Thanks for your fast answer. If I can do what you says, it will really helps me.

Emmanuel

p.s.: I posted twice... sorry... moderator?


Top
 Profile  
 
 Post subject: Re: StaleObjectStateException on flush
PostPosted: Thu Dec 21, 2006 12:54 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
try
Code:
Transaction transaction = null;
try {
  SupplierDao supplierDao = SuppliersEMDaoFactory.getInstance().getSupplierDao();
          
  Session hibernateSession = ServiceLocator.getCurrentSession();
  transaction = hibernateSession.beginTransaction();

  Supplier supplier = new Supplier();
  supplierDao.generateKey(supplier);
                     
  supplier.setName("Name1");
          
  hibernateSession.saveOrUpdate(supplier);

hibernateSession.refresh(supplier) //Add this          
  supplier.setName("Name2"); // bad code

  hibernateSession.flush();
  transaction.commit();
         
}
catch (Exception e) {
  e.printStackTrace();
  transaction.rollback();
}


[/quote]

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 12:58 pm 
Newbie

Joined: Wed Dec 20, 2006 10:52 pm
Posts: 7
Not working... now I have :

Code:
org.hibernate.HibernateException: this instance does not yet exist as a row in the database
   at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:90)
   at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:39)
   at org.hibernate.impl.SessionImpl.fireRefresh(SessionImpl.java:902)
   at org.hibernate.impl.SessionImpl.refresh(SessionImpl.java:886)
   at net.cpaerp.suppliers.application.presentation.TestExecute.execute(TestExecute.java:74)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)

when refresh is executed.


Top
 Profile  
 
 Post subject: Re: StaleObjectStateException on flush
PostPosted: Thu Dec 21, 2006 1:16 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
doh... try this istead
Code:
Transaction transaction = null;
try {
  SupplierDao supplierDao = SuppliersEMDaoFactory.getInstance().getSupplierDao();
          
  Session hibernateSession = ServiceLocator.getCurrentSession();
  transaction = hibernateSession.beginTransaction();

  Supplier supplier = new Supplier();
  supplierDao.generateKey(supplier);
                     
  supplier.setName("Name1");
          
  hibernateSession.saveOrUpdate(supplier);
 
  hibernateSession.flush()
 
   hibernateSession.refresh(supplier) //Add this          
  supplier.setName("Name2"); // bad code

  hibernateSession.flush();
  transaction.commit();
         
}
catch (Exception e) {
  e.printStackTrace();
  transaction.rollback();
}



PS: i dint quite understand why you are saving it ..and overwriting it just after save ??

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 1:27 pm 
Newbie

Joined: Wed Dec 20, 2006 10:52 pm
Posts: 7
I don't want to flush before updating it. I just want to save it.

This is just an example, the reality is that these changes are made in 2 requests.

First I create the supplier (forget "name1", it's just here to see what it insert in the database) in the first request, instanciating it and attaching it with hibernate (with the saveOrUpdate method).

Second, the supplier is returned to the client in a jsp with all other suppliers already fetched. The user can then modify every supplier it wants.

Third, the form is posted by the user, and an update action make a get on the hibernate session to return every supplier, update it, and finally commit changes.

The "get" takes the objects in the cache, without worrying about the existence or not in the database. Even the new supplier instance is returned and everything works fine, since I flush the change.

There is a thing I don't understand. Check at my log with the column binding (read from botton) :

Code:
Error   8600.766   true   org.hibernate.event.def.AbstractFlushingEventListener   Could not synchronize database state with session
Debug   8600.734   false   org.hibernate.type.TimestampType   binding '2006-12-21 12:13:17' to parameter: 5
Debug   8600.719   false   org.hibernate.type.StringType   binding 'a600a0abffffff80001383eb4d277804' to parameter: 4
Debug   8600.719   false   org.hibernate.type.StringType   binding null to parameter: 3
Debug   8600.688   false   org.hibernate.type.StringType   binding 'Name2' to parameter: 2
Debug   8600.688   false   org.hibernate.type.TimestampType   binding '2006-12-21 12:13:20' to parameter: 1
Debug   8600.656   false   org.hibernate.SQL   
    update
        Supplier
    set
        timestamp_column=?,
        name=?,
        telephone=?
    where
        uniqueId=?
        and timestamp_column=?
Debug   8600.609   false   org.hibernate.type.StringType   binding 'a600a0abffffff80001383eb4d277804' to parameter: 4
Debug   8600.594   false   org.hibernate.type.StringType   binding null to parameter: 3
Debug   8600.594   false   org.hibernate.type.StringType   binding 'Name1' to parameter: 2
Debug   8556.047   false   org.hibernate.type.TimestampType   binding '2006-12-21 12:13:17' to parameter: 1
Debug   8552.828   false   org.hibernate.SQL   
    insert
    into
        Supplier
        (timestamp_column, name, telephone, uniqueId)
    values
        (?, ?, ?, ?)


This is supposed to work!! Even if 2 database access is not good thing according to me. How the core checks for stale objects?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 2:24 pm 
Newbie

Joined: Wed Dec 20, 2006 10:52 pm
Posts: 7
A little update on my investigation:

I traced the hibernate code to see why it throws that exception even if the sql statements seems to be ok.

The second sql statement (the update), is executed in the AbstractEntityPersister class, in the method update(). Logic.

The code looks like this :

return check( update.executeUpdate(), id, j, expectation, update );

the update object is my update prepared statement, who, as I posted before, should be ok. The return of the executeUpdate() method (the number of record updated, is sent to a check method, who throw my #%$#ing exception.

This check method verify that the number of rows updated is equal to 1. But the update.executeUpdate() method return 0. So now my question is : Why the executeUpdate returns 0, when it appears to be an evidence that it really is a row updated, the row that was just inserted.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 4:23 pm 
Newbie

Joined: Wed Dec 20, 2006 10:52 pm
Posts: 7
Ok...

I finally found it!

The problem is with Oracle!! Again!!

Every sql query with a timestamp in a where clause return nothing with the jdbc drivers of Oracle even if the row exists, is commited and present since 200 years!! With any other database, it works fine!

So the bug is inside the jdbc drivers of Oracle! I changed my architecture to a number versioning, and screw oracle.

And party time!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.