I have created a trigger so that my entities ids are autogenerated with a sequence each time they're inserted into my Oracle database.
The problem comes with annotating these entities for Hibernate/JPA: I need to define a @GeneratedValue
annotation but I don't want to specify the sequence name -- doing that will make Hibernate query the sequence first, then insert, which is a work that is already done by the trigger.
Is there any way to skip this sequence in the @GeneratedValue with the scenario I've proposed?
Exception I get if id is not provided:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): Pattern
Pattern class:
@Entity
@Table(name = "PATTERN")
public class Patron extends HistoricoAbstractEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID_PATTERN")
private Integer idPattern;
@Column
private String description;
@Column(name = "NEGATIVE")
private Boolean isNegative;
@Column(name = "type")
private Integer type;
@Column(name = "N_DAYS")
private Integer numDays;
... (getters & setters)
}