In our old architektur we used id's like this:
/**
* Model for each database-object
*/
public abstract class AbstractDbBase {
@Getter
@Setter
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
@Column(nullable = false, unique = true, updatable = false)
private Long id;
}
But we got some issues, while changing values outside of Hibernate.
So we decide to use bigserial
from postgres
.
We changed our database and added for a each table a seqeunce and set it as primary key.
We have a lot of entities and all of them using the AbstractDbBase
. And in AbstractDbBase
is the defintion of the id.
But now we cant set Hibernate to use the sequence correctly.
We tried the following stragegies (for the @GeneratedValue()
-annotation):
GenerationType.IDENTITY
: Throws excepetion when create records over hibnerate (no access to the sequence).GenerationType.SEQUENCE
: Throws validation-exception (no sequence found).GenerationType.AUTO
: Throws validation-exception (no sequence found).
My question is: How we can tell Hibernate to use the correct sequence? (Without write explicit the sequence-name for each entity)