miércoles, 13 de mayo de 2015

Using @GeneratedValue with Firebird and JPA (EclipseLink)

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

  • Specify a name for your Sequence
     @SequenceGenerator( name = "YOUR_SEQUENCE_NAME", sequenceName = "YOUR_GENERATOR", allocationSize = 1 )
  • Use GeneratedValue and assign previous name to generator property
 @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "YOUR_SEQUENCE_NAME" )   
 
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.

jueves, 26 de marzo de 2015

HTML Report from MySQLWorkbench 6.x Schema Model

This begun in 2010 when I started to create a Lua script to generate an HTML report from MySQLWorkbench 5.x (http://tmsanchezdev.blogspot.mx/2010/07/reporte-en-html-de-un-modelo-en.html).

Lua support has been removed from MySQLWorkbench and now we can use Python to generate plugins.

I updated the script to use phyton. Script is available here for download.
 
Update: I added both scripts in github, feel free to contribute https://github.com/tmsanchez/workbenchscripts
 
Update May 15th 221: for MySQLWorkbench 8.x check this http://tmsanchezdev.blogspot.com/2021/05/updated-plugings-for-mysqlworkbench-8x.html  
 
To Install the plugin go to Scripting / Install Plugin/Module then select HTMLShemaReport.py file and restart MySQL Workbench


Open your model and go to Tools / Catalog and select "Database schema in HTML format" and provide a file name in save dialog.



Once document has been generated you will see following message:

Then open your HTML document and see the report:

Finally I want to thank all readers for their contributions, specially to Rodrigo Schmidt who started script python.