How to include sequence in WebService Restful

1

I have created a database in Oracle 11G , where there is a sequence to make the autoincrementable records:

CREATE SEQUENCE S_CATEGORIA MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE;

Through a webservice I need to save a new record to the category table, in this there is no problem without using the sequence.

This is the structure I use to send:

<categorias>
 <categoriaId>1</categoriaId> //ID de la categoria, aqui debo utilizar la secuencia
 <descripcion>Aceites</descripcion> //Descripcion
</categorias>

How could I send the data so that I consider using the sequence that is in the BD ??

Thanks for your help ... Greetings _!

    
asked by Jonathan 11.04.2018 в 22:54
source

1 answer

1

Most times you have to make adjustments to the Entity that the mappings in netbeans are generated because they do not add fields that are autoincrementable or when we have a table where we keep our sequence that information we must Add it with annotations I'll give you two examples:

@Entity
@Table(name = "CATEGORIAS" , schema = "tutorial")
@SequenceGenerator(
name="secuenciaCategoria",
sequenceName = "S_CATEGORIA",
initialValue = 1, 
allocationSize = 10
)
public class Categorias {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "secuenciaCategoria")
private Long id;
private String name; 
}

This other example is when you use a table with the sequences, the name of the table is SGU_SECUENCIAS

@Id
@Basic(optional = false)
@NotNull
@Column(name = "ID_ACCION", nullable = false)
@GeneratedValue(generator = "ACCION_GEN")
@TableGenerator(name = "S_CATEGORIA", table = "SGU_SECUENCIAS",
        pkColumnName = "NOMBRE", valueColumnName = "VALOR",
        pkColumnValue = "SguAccion", allocationSize = 1)

private Integer idAccion;
    
answered by 12.04.2018 / 17:05
source