reza ramezani matin
reza ramezani matin

Reputation: 1474

Schema attribute of @SequenceGenerator does not work in Hibernate

There is an oracle user where some objects are common between other users. Due to this fact, the application.yml is like this following:

jpa:
    hibernate:
        ddl-auto: update
    properties:
      hibernate:
        dialect: org.hibernate.dialect.Oracle10gDialect
        default_schema: common_user
        show_sql: true

Any objects such as Entity that must be in its own user is declared with schema attribute of @Table-annotation like this following:

@Entity
@Table(name = "NET_EVL_TEMPLATE", schema = "NET")
@SequenceGenerator(name = "sequence_db", sequenceName = "SEQ_NET_EVL_TEMPLATE", allocationSize = 1)
@Getter
@Setter
public class Evaluation extends BaseEntity<Long> {
...

This scenario is worked rightly for Table but it is not worked for sequence; another hand all sequence of all user is generated in the common user. I put schema in the sequence attribute like this:

@SequenceGenerator(name = "sequence_db", sequenceName = "SEQ_NET_EVL_TEMPLATE_TREE", allocationSize = 1, schema = "NET")

But it again does not work and it again is generated in the common user.

How do I fix my problem? Another hand the sequence-object of any user is generated to its own user instead of common user.

Upvotes: 2

Views: 1381

Answers (2)

ali akbar azizkhani
ali akbar azizkhani

Reputation: 2289

You can set schema name to sequence name like this

@Entity
@Table(name = "NET_EVL_TEMPLATE", schema = "NET")
@SequenceGenerator(name = "sequence_db", sequenceName = "NET.SEQ_NET_EVL_TEMPLATE", allocationSize = 1)
@Getter
@Setter
public class Evaluation extends BaseEntity<Long> {
...

Upvotes: 1

Vlad Mihalcea
Vlad Mihalcea

Reputation: 154090

Most likely it's an issue. You need to replicate it with this test case template and open a Jira issue:

http://in.relation.to/2018/06/04/best-way-write-hibernate-orm-issue-test-case/

Upvotes: 0

Related Questions