persistence@glassfish.java.net

How to use discriminator type with integer?

From: Sherry Shen <Sherry.Shen_at_Sun.COM>
Date: Tue, 05 Sep 2006 12:17:04 -0700


In my test, the discriminator type is INTEGER.

1) The discriminator in DDL file by Java2DB is VARCHAR.  
Does this work by design?

2) When the discriminator value is given as "ABC",
there is no exception. 
Is this correct?

3) In Spec 9.1.31, Discriminator Value Annotation,
"If the discriminator type is an integer, the value specified
must be able to converted to an integer value (e.g., "1")."
Does it refer to the usage of @DiscriminatorValue("1") ?

Thanks for the help!

Sherry

PS: my test
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="DCOL",
           discriminatorType=DiscriminatorType.INTEGER)
public class BaseInfo implements java.io.Serializable {

@Entity
@DiscriminatorValue("ABC")
public class ClientInfo extends BaseInfo {

% more createDDL.jdbc
CREATE TABLE BASEINFO (ID VARCHAR(255) NOT NULL,
   DCOL VARCHAR(31), NAME VARCHAR(255), PRIMARY KEY (ID))
CREATE TABLE CLIENTINFO (ID VARCHAR(255) NOT NULL,
   PROP2 VARCHAR(255), PRIMARY KEY (ID))
ALTER TABLE CLIENTINFO ADD CONSTRAINT FK_CLIENTINFO_ID
   FOREIGN KEY (ID) REFERENCES BASEINFO (ID)
%

[TopLink Fine]: 2006.09.05 09:08:42.334--ClientSession(33492446)
--Connection(32603767)--Thread(Thread[main,5,main])
--INSERT INTO BASEINFO (ID, NAME, DCOL) VALUES (?, ?, ?)
        bind => [foo, Sherry, ABC]
[TopLink Fine]: 2006.09.05 09:08:42.423--ClientSession(33492446)
--Connection(32603767)--Thread(Thread[main,5,main])
--INSERT INTO CLIENTINFO (PROP2, ID) VALUES (?, ?)
        bind => [myP2, foo]