5 Replies Latest reply on Jul 28, 2009 1:31 AM by guy_cole

    entity update on postgres corrupts booleans

    guy_cole

      Hello, everybody.


      When my application does a SQL update on an entity, it always writes the boolean columns as false.  Insert is OK, select is OK.


      Any suggestions on how to fix or mitigate this issue?


      Another point: I'm not actually forcing the update.  When I fetch a lazy collection, after the fetch there is a update (which corrupts my boolean values).  Not sure if the update is a clue or just normal behavior.


      My environment:
      Ubuntu 8, Sun JDK 1.5.0.17, PostGreSQL 8.3.7 w/JDBC 8-4-701, JBoss 4.2.4.GA (built from source) and Seam 2.1.2


      Thank you very much.

        • 1. Re: entity update on postgres corrupts booleans
          asookazian

          so your question becomes what is the root cause of the following behavior:



          When I fetch a lazy collection, after the fetch there is a update (which corrupts my boolean values).

          Are you using JPA with Hibernate as persistence provider or other provider?  Are you using AUTO, COMMIT, or MANUAL flushMode?  Show code example.


          If you have time, etc., using hbm2ddl (Hibernate Tools) you can forward-engineer your JPA entities into a different db (like mysql, MSSQL, etc.) and see if you can reproduce the behavior.

          • 2. Re: entity update on postgres corrupts booleans
            guy_cole

            OK, I fixed it. 


            Thank you very much for your prompt and appropriate response.


            I switched flush-mode to MANUAL (from the conversation) and now it seems to behave properly.


            To answer your other questions, it is JPA and the code is not very interesting.  Something like this:


            public class Entity {
              boolean flag
              //setter and getter for flag


              @OneToMany(yadda...)
              public Set getCollection() { }
              public void setCollection(Set arg) { }
            }


            I call the collection from a toggle panel, which reads the collection (for display as a table).  After the read, there would be a gratuitous update w/bad boolean values written to DB.


            I can send you something prettier if you like.


            Thank you very much.  I spent all day yesterday trying to figure this out.  Great relief to have a simple solution.

            • 3. Re: entity update on postgres corrupts booleans
              asookazian

              It's very important to understand why that fixed it (i.e. what is the difference b/n AUTO and MANUAL?) 


              You should typically use MANUAL in Seam apps (if Hibernate is your persistence provider) as it enables you to achieve the atomic conversation covered in SiA book.


              We typically use SMPC (@In EntityManager entityManager;) with MANUAL flush in our conversation modeling...

              • 4. Re: entity update on postgres corrupts booleans
                swd847

                Are you sure it is fixed? When you manually do entityManager.flush() does it write the booleans ok?


                If there is still a problem can you post how your booleans are mapped?

                • 5. Re: entity update on postgres corrupts booleans
                  guy_cole

                  Yes, quite sure joining the conversation cures this issue.


                  I don't do a flush() because I don't ask for the update.  The update was just something which happened after I read the collection.


                  I'm guessing that without the join/conversation, something decided the entity was dirty and required synchronization (after doing the lazy collection read).  I spent a lot of time on this.  Only booleans were corrupted.  Strings and integers were fine.


                  Now w/a conversation, there isn't any update and no chance of corruption.


                  Originally, I didn't join a conversation from this page because there is not any editing, only viewing.  Some parts of the page are in (a closed) simpleTogglePanel.  The collection is read when the panel is opened, causing a select and then a gratuitous update.


                  Now I have a join conversation around the page and it works.


                  Thanks for asking, hope this answers your question.