0

It should be easy. Oracle has defined "generate always" for an id column. So there is no need to add this id to the insert statement. How do i define my entity that it is handling right.

@Entity
public class Example {

   @Id
   @GeneratedValue // if i remove this annotation than hibernate complains that i need to set it manually 
   @Column(name="ID", insertable=false, updatable=false)
   private Long id;


} 

in the error message i see that it still tries to add the id to the query.

My work-around for the column. Add the @id to an other column and remove the id column from entity definition :-D

  • Why do you care if the id is part of the insert? – Jens Schauder Mar 18 '22 at 08:13
  • @JensSchauder If the `id` column is defined as `GENERATED ALWAYS AS IDENTITY` then using `INSERT INTO table_name (id, value) VALUES (1, 'aaa');` will fail with `ORA-32795: cannot insert into a generated always identity column` you need to either exclude the `id` column and just insert the other values or use `INSERT INTO table_name (id, value) VALUES (DEFAULT, 'aaa');` [db<>fiddle](https://dbfiddle.uk/?rdbms=oracle_21&fiddle=54ec4b14baafcadcfc0ecbb2a35e1c2e) – MT0 Mar 18 '22 at 10:19
  • The easy fix seems to be to remove the `ALWAYS`, wouldn't it? – Jens Schauder Mar 18 '22 at 10:33
  • Seems to be a duplicate of [this](https://stackoverflow.com/a/57767572/4808122) question. Use Hibernate 5.3+ and `GenerationType.IDENTITY` – Marmite Bomber Mar 18 '22 at 12:12

0 Answers0