3 Replies Latest reply on Feb 13, 2003 7:12 AM by scoy

    CMP converts empty string to space

    jameshr

      We run jboss-3.0.2 on Win2000 using SqlServer7. The problem occurs when we invoke a CMP getter on a varchar database column whose value is the empty string (ie length 0). Instead of returning an empty string, the getter returns a space, length 1. Non-zero length values and null values behave fine. As a work-around, we have been plugging trim()'s in the getter's.

      This CMP issue is inconsistent in nature. For example, if the table Facility has 5 varchar fields, this behavior may only be exhibited in only 1 or 2 fields, in this case the Contact field. I would have expected to see the issue across all 5 fields.

      Also, if I add a Facility record leaving Facility.Contact empty and then retrieve the record, I note the data looks fine. An update operation gives the same result. But, if I stop/restart JBoss and then retrieve the data, the problem occurs. This tells me that it's an issue related to the CMP JDBC code that retrieves data from the database into the bean.

        • 1. Re: CMP converts empty string to space
          scoy

          It's highly unlikely that the CMP engine is doing this, otherwise I'm sure there would be a LOT more complaints.

          It may possibly be your JDBC driver - make sure it is current.

          Alternatively, there is something strange with your data mappings (java type <-> SQL column) that is causing some kind of data conversion to happen.

          I suspect that the JDBC driver is messing up the USASCII <-> Unicode translation of strings.

          Steve

          • 2. Re: CMP converts empty string to space
            jameshr

            Thanks Steve. Afterwards, I did realize that pure JDBC had the same issue. We use Ashna drivers. Can you recommend a popular/stable free JDBC driver?

            • 3. Re: CMP converts empty string to space
              scoy

              Sorry, I don't use this product.

              I suggest a google search, or possibly ask this specific question in the forum under a new topic, such as "JDBC driver recommendations for SQL Server 7?"

              Steve