2 Replies Latest reply on Oct 3, 2005 5:17 AM by anthropophagos

    CMP: Irregular updates of database??

    anthropophagos

      Hi,

      Basically I have I Bean which stores a Serializeable Object in a MySql Database using JBoss 4.0.2.
      What I do not understand is, that in some instances changes to the object are not saved to the Database. There is no SQL UPDATE query generated in the server.log file (DEBUG messages turned on, of course).

      So basically my question would be, how I can regulate the time JBoss writes to the Database. And how I can influence that time interval.
      I looked around the forum but did not seem to find anything. Would be great if somebody could shed some light on this.

      Thank you,
      Jannis

        • 1. Re: CMP: Irregular updates of database??
          acoliver

          The scope of the transaction governs the commit. Execution of finders forces a flush.

          At this point you should probably be looking to move to Hibernate or EJB3. I'd say that the bulk of newer JBoss-based systems (if not on the whole) are now deployed using Hibernate or similar and not CMP2. The EJB3 persistence model is essentially Hibernate.

          • 2. Re: CMP: Irregular updates of database??
            anthropophagos

            Thank you for your response!

            I managed to narrow my problem to the following:

            There is a CMP field
            getVersionHash()
            setVersionHash()

            which contains a java.util.HashMap <Integer, VersionInfo>

            VersionInfo is a class which looks like this:

            public class VersionInfo implements java.io.Serializable{
            private static final long serialVersionUID = 123567890L;
            public String user = null;
            public long version = 0;
            public long lastUserVersion = 0;
            }

            What I do not understand now is the following problem:

            HashMap verMap = getVersionHash();
            VersionInfo verInfo = (VersionInfo)verMap.get(typeCode);

            //verInfo.version = verInfo.version+1; // NO SQL UPDATE
            //verMap.put(typeCode, verInfo);

            VersionInfo newVer = new VersionInfo(); // SQL UPDATE
            newVer.user = verInfo.user;
            newVer.lastUserVersion = verInfo.lastUserVersion;
            newVer.version = verInfo.version+1;
            verMap.put(typeCode, newVer);

            If the first approach is being used, there is no SQL UDATE at all, meaning the occured change to the Hash is NEVER commited to Database

            If I use the second approach, changes to the Hash are commited to Database immediately.

            Am I missing anything? what's wrong?

            Thank you in advance,
            Jannis