Skip to main content

Sequencing query

5 replies [Last post]
dibyendumajumdar
Offline
Joined: 2005-01-15

Hello,

Is there any documentation on how Glassfish handles various sequencing options?

I am testing EJB with Apache Derby, and am a bit puzzled by following:

1. Apache Derby supports autoincrement columns, but Glassfish seems to use a Sequence table instead of native sequencing even when generate is set to AUTO.

2. The SEQUENCE table is generated in the default schema - how can one specify the schema for this? I have worked around this issue by specifying the schema name as the JDBC connect id.

3. There does not appear to be any primary key on the SEQUENCE table. Is this correct? I have seen multiple rows being inserted into the table with the same Sequence name.

Regards

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dibyendumajumdar
Offline
Joined: 2005-01-15
gyorke
Offline
Joined: 2005-06-21

Hello,
There a few different issues here, one is GeneratorType.AUTO which is poorly defined in the Specification. It is currently under review by the committee and until it is finalized I do not recommend using it. Table Generation is chosen because it is the only type available on all databases where the user created artifact (the table) can be shared by the Persistence Provider. Sequence objects should not be commandeered by the Persistence Provider for other class types and Identity Fields are not available on all databases.

Second if you are finding issues with the DDL generation please file issues in the GlassFish issue tracker with specific examples.
Thanks,
--Gordon

dibyendumajumdar
Offline
Joined: 2005-01-15

Thanks for replying to my query.

The spec says that with AUTO the "provider should pick an appropriate strategy for the particular database". I take this to mean that the provider is free to use SEQUENCE if that is supported by DBMS, or IDENTITY if that is supported. In other words, my interpretation of AUTO would be to use the best available native strategy for the particular DBMS.

I will raise an issue for the DDL generation problems.

Regards

Dibyendu

dibyendumajumdar
Offline
Joined: 2005-01-15

Okay, here is a bit more I have found out by trial and error.

I can get the SEQUENCE table created in the schema I want by using the TableGenerator annotation. Example:

@TableGenerator(name="IDGEN", table=@Table(name = "SEQUENCE", schema = "JS"),
pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="JOBID_SEQUENCE", allocationSize=10)

I can then use this in the entity as follows:

@Id(generate=GeneratorType.TABLE, generator="IDGEN")
public Long id;

I also tried to use the IDENTITY column feature in Derby. This works okay with GeneratorType.IDENTITY, however, Schema Generation loses the IDENTITY column so you have to create the table manually.

The plain @Id annotation seems counter-intuitive. Since the default GeneratorType is NONE, and documentation says that this means no primary key generation, I was puzzled to see that the SQL generated by Toplink attempts to set the Id column to NULL. This causes Derby to throw an Exception.

Regards

dibyendumajumdar
Offline
Joined: 2005-01-15

Ignore my comment about the use of plain @Id - I misunderstood how it works.