OpenJPA
  1. OpenJPA
  2. OPENJPA-1224

OpenJPA MySQL BigDecimal ignoring Precision/Scale column Annotation when generating tables

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.3.0, 2.0.0-beta
    • Component/s: jpa
    • Labels:
      None
    • Environment:
      OpenJPA 1.2.1, MySQL 5.1.32 (InnoDB),

      Description

      Create an entity with a BigDecimal member. Using runtime enhancement and automatic schema generation. When OpneJPA creates the table it creates a column of type DECIMAL but will always ignore the precision set on the column annotation and use the default of (10,0) causing BigDecimal data to round up to the nearest whole number.

      Sample of basic Entity:

      @Entity
      public class Asset implements Serializable{
      private static final long serialVersionUID = 1L;

      @Id
      @GeneratedValue(strategy=SEQUENCE, generator="ASSET_SEQ")
      private String uniqueid;

      @Column(precision=10,scale=6,)
      private BigDecimal rate;

      public Asset()

      { this.rate = rate; }

      public void setRate(BigDecimal rate) { this.rate = rate; }

      public BigDecimal getRate()

      { return rate; }

      }

      Code to generate schema and save entity:

      Asset asset = new Asset();
      asset.setRate(BigDecimal bd = new BigDecimal(100.004));

      Now called persist/merge on the entity to generate the table schema and save the entity. The table is generated and the "rate" column is set to type DECIMAL(10,0) instead of DECIMAL(10,6). The table create script looks like this:
      DROP TABLE IF EXISTS `trm`.`asset`;
      CREATE TABLE `trm`.`asset` (
      `uniqueid` varchar(255) NOT NULL,
      `rate` decimal(10,0) NOT NULL,
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

      doubles work ok.

        Issue Links

          Activity

          Hide
          Jorge Urdaneta added a comment -

          I have the same problem when using hibernate as my JPA provider.
          It seems that both projects doesn't include money handlers test cases.

          By now i'm editing the database schema by hand after automatic table creation occurs.

          Show
          Jorge Urdaneta added a comment - I have the same problem when using hibernate as my JPA provider. It seems that both projects doesn't include money handlers test cases. By now i'm editing the database schema by hand after automatic table creation occurs.
          Hide
          Rick Curtis added a comment -

          The original issue reported by this JIRA has been fixed in trunk and 1.3.x.

          Show
          Rick Curtis added a comment - The original issue reported by this JIRA has been fixed in trunk and 1.3.x.
          Hide
          Xiaoqin Feng added a comment -

          I am on vacation from 12/20/2009  to 12/26/2009.

          If you have any question on deployment and JEE bugs, please contact Saurabh Arora or my manager Maruthi Nuthikattu.

          For emergency, contact me at 925-209-5517.

          Show
          Xiaoqin Feng added a comment - I am on vacation from 12/20/2009  to 12/26/2009. If you have any question on deployment and JEE bugs, please contact Saurabh Arora or my manager Maruthi Nuthikattu. For emergency, contact me at 925-209-5517.

            People

            • Assignee:
              Rick Curtis
              Reporter:
              Christopher Davies
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development