lunes, 14 de noviembre de 2011

Valores Autogenerados Firebird 2.1 y EclipseLink (JPA 2.0)

1.-Crear Generador en Firebird

CREATE SEQUENCE GEN_CO_GRUPO;
ALTER SEQUENCE GEN_CO_GRUPO RESTART WITH 0;

/* Old syntax is:
CREATE GENERATOR GEN_CO_GRUPO;
SET GENERATOR GEN_CO_GRUPO TO 0;
*/

2.-Crear Entidad en Java

En esta clase Java hacer referencia al Generador de firebird...

*
*@author hacosta
*/
@Entity
@Table(name="CO_GRUPO")
@SequenceGenerator(sequenceName="GEN_CO_GRUPO",name="Grupo_Seq",allocationSize=1)
@NamedQueries({
@NamedQuery(name="CoGrupo.findAll", query = "SELECT c FROM CoGrupo c")})
public class CoGrupo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator="Grupo_Seq",strategy=GenerationType.SEQUENCE)
@Basic(optional= false)
@NotNull
@Column(name="ID", nullable = false)
private Integer id;
@Size(max= 50)
@Column(name="NOMBRE", length = 50)
private String nombre;

No hay comentarios:

Publicar un comentario