If you need to manage generated values in a Java application that uses JPA (Java Persistence API) and FirebirdSQL as database you can use @GeneratedValue annotation according to EclipseLink.
All you need to do is follow these steps:
1. Create your FIREBIRD generator
-- create your generator
CREATE GENERATOR GEN_ORDER;
SET GENERATOR GEN_ORDER TO 0;
If you are using FirebirdSQL 2.0 you can use CREATE SEQUENCE http://www.firebirdsql.org/refdocs/langrefupd20-create-seq.html
-- For Firebird 2.x
CREATE SEQUENCE GEN_ORDER;
ALTER SEQUENCE GEN_ORDER RESTART WITH 0;
2.Use @SequenceGenerator and @GeneratedValue in your Entity class
For example to use Firebird generator defined in Step 1 use this lines:
@SequenceGenerator( name = "ORDER_SEQUENCE", sequenceName = "GEN_ORDER", allocationSize = 1 )
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "ORDER_SEQUENCE" )
Finally your java class looks like this:
I hope this can help you.
All you need to do is follow these steps:
1. Create your FIREBIRD generator
-- create your generator
CREATE GENERATOR GEN_ORDER;
SET GENERATOR GEN_ORDER TO 0;
If you are using FirebirdSQL 2.0 you can use CREATE SEQUENCE http://www.firebirdsql.org/refdocs/langrefupd20-create-seq.html
-- For Firebird 2.x
CREATE SEQUENCE GEN_ORDER;
ALTER SEQUENCE GEN_ORDER RESTART WITH 0;
2.Use @SequenceGenerator and @GeneratedValue in your Entity class
- Specify a name for your Sequence
- Use GeneratedValue and assign previous name to generator property
For example to use Firebird generator defined in Step 1 use this lines:
@SequenceGenerator( name = "ORDER_SEQUENCE", sequenceName = "GEN_ORDER", allocationSize = 1 )
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "ORDER_SEQUENCE" )
Finally your java class looks like this:
I hope this can help you.