0

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)

akop
  • 5,981
  • 6
  • 24
  • 51

1 Answers1

0

I found this: hibernate could not get next sequence value

So I have to use GenerationType.IDENTITY. Now I have to solve the "no permission for the sequence"-issue. This have I done with this question: ERROR: permission denied for sequence cities_id_seq using Postgres

It works now.

akop
  • 5,981
  • 6
  • 24
  • 51