Columna de clave principal de anotación de Hibernate sin incremento automático

I want to map a column from my database as primary key which is not auto-increment. Please suggest me how to create hibernate annotation for this column

preguntado el 27 de noviembre de 13 a las 05:11

Bydefalut primary key column is not auto-increament untill you add any annotation for making it auto-increment -

but when I try to insert in database it is executing select query with this primary key column in the where clause -

1 Respuestas

Use @Id annotation which defines the mapping of that property to the primary key column. Don't use @GeneratedValue annotation.

@Column(name = "id")
Integer id;

respondido 27 nov., 13:05

When doing this as you suggested as I try to insert in database it is executing select query - Ashish Nayal

when I am using @generatedvalue for primary key the insert query is executing correctly but otherwise not - Ashish Nayal

as you said your primary key column is not auto-increment, you need to set primary key during insert operation. But if you want hibernate to set primary key then use @generatedvalue which is you said have been using. - Vipul Paralikar

when I am giving primary key value from user interface,and inserting it using hibernate with annotation it is not executing insert query.Is it necessary in hibernate that we cannot assign value to primary key it is auto generated. - Ashish Nayal

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.