This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 153562

Summary: Primary Keys Forced to BigDecimals, again
Product: javaee Reporter: stevear <stevear>
Component: PersistenceAssignee: Dongmei Cao <dongmeic>
Status: REOPENED ---    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description stevear 2008-11-20 16:59:48 UTC
In code generation ("Generate JSF pages from Entities..."), numeric columns with 0 scale are being forced to BigDecimal
in regular entity classes, but not in embedded compound-pk classes (*PK.java).  This causes compile errors in
controllers because of the type mismatches (cannot accept BigDecimals to set BigIntegers).  Ideally, numeric pk columns
in entity classes would be BigInteger (as in the embedded key classes already), not BigDecimals.   

This is essentially a duplicate of issue 113701, which is marked fixed, yet this is happening for me on a fresh install
of NetBeans IDE 6.5 (Build 200811100001) against an Oracle 10 database.

Example of such a column in a regular entity:
    @Id
    @Basic(optional = false)
    @Column(name = "ID", nullable = false, precision = 22, scale = 0)
    private BigDecimal id;

Example of such a column (also precision 22, scale 0), in a compound-pk entity:
  @Basic(optional = false)
  @Column(name = "DERIVATION_ID", nullable = false)
  private BigInteger derivationId;
Comment 1 stevear 2008-11-20 17:02:37 UTC
> Ideally, numeric pk columns in entity classes would be BigInteger

I meant, if they have scale 0
Comment 2 Dongmei Cao 2008-11-25 00:54:33 UTC
I can not reproduce your issue. I tried with the NetBeans 6.5 and the latest dev build. Both the regular entity class
and the PK class use BigInteger
Comment 3 Dongmei Cao 2008-11-25 00:58:08 UTC
Here is the database table I tried
CREATE TABLE "BUG153562_TABLE"
   (	"ID" NUMBER(22,0) NOT NULL ENABLE,
        "DERIVATION_ID" NUMBER(22,0) NOT NULL ENABLE,
	"COLUMN2" NUMBER(22,0),
	CONSTRAINT "TABLE1_PK" PRIMARY KEY ("ID", "DERIVATION_ID")
   );

Here's the generated code:
public class Bug153562Table implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected Bug153562TablePK bug153562TablePK;
    @Column(name = "COLUMN2")
    private BigInteger column2;
......
}

public class Bug153562TablePK implements Serializable {
    @Basic(optional = false)
    @Column(name = "ID", nullable = false)
    private BigInteger id;
    @Basic(optional = false)
    @Column(name = "DERIVATION_ID", nullable = false)
    private BigInteger derivationId;
........
}
Comment 4 Dongmei Cao 2008-11-25 00:59:44 UTC
Please provide me more info, such as, the SQL script, what kind of project you used, etc, if you still see the problem.
Comment 5 Dongmei Cao 2008-12-02 21:32:19 UTC
If you still see the problem, please reopen it with a reproducible case.
Comment 6 ggonzalo 2017-04-25 17:01:36 UTC
This problem is happening again in version 8.

Here the reproducible case using Oracle 11gXE and Netbeans 8.2 in MacOS Sierra:

CREATE TABLE "TEST" 
(
  "ID" NUMBER(38,0) NOT NULL ENABLE, 
  "CREATION" DATE NOT NULL ENABLE, 
  "CREATION_USR" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  CONSTRAINT "TEST_PK" PRIMARY KEY ("ID") ENABLE
);

And the generated class is:

@Entity
@Table(name = "TEST")
public class Test implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private BigDecimal id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CREATION")
    @Temporal(TemporalType.TIMESTAMP)
    private Date creation;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "CREATION_USR")
    private String creationUsr;

    public Test() {
    }

    ...
}

and another case, when is and Embeddable PK is using BigInteger, if ID is the same in table TEST and TEST2 is causes problems:

CREATE TABLE "TEST2" 
(
  "ID1" NUMBER(38,0) NOT NULL ENABLE, 
  "ID2" NUMBER(38,0) NOT NULL ENABLE, 
  "CREATION" DATE NOT NULL ENABLE, 
  "CREATION_USR" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  CONSTRAINT "TEST2_PK" PRIMARY KEY ("ID1","ID2") ENABLE
);

and the class generated:

@Entity
@Table(name = "TEST2")
public class Test2 implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected Test2PK test2PK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CREATION")
    @Temporal(TemporalType.TIMESTAMP)
    private Date creation;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "CREATION_USR")
    private String creationUsr;

   ...
}

@Embeddable
public class Test2PK implements Serializable {

    @Basic(optional = false)
    @NotNull
    @Column(name = "ID1")
    private BigInteger id1;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID2")
    private BigInteger id2;

   ...
}