简体   繁体   中英

Oracle JPA GenerationType.AUTO with generator asks for “hibernate_sequence”

I'm trying to use a defined sequence generation in Oracle JPA, along with GenerationType.AUTO like this:

@Id
@SequenceGenerator(name = "MY_GEN_NAME", sequenceName = "MY_SQ_NAME")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "MY_GEN_NAME")
@Column(name = "ID", nullable = false)
private Long id;

After running the hibernate validation it throws an error:

Schema validation: missing sequence [hibernate_sequence]

I guess, it is ignoring my MY_GEN_NAME and trying to use that global sequence for id generation.

When I switch to GenerationType.SEQUENCE , it uses SequenceHiLoGenerator and it works fine.

Why is that happening, and is it possible to make the GenerationType.AUTO work with given sequence for Oracle (possibility to switch to other db)?

AUTO says to the JPA provider, "choose what you want", and it will not use the "generator" attribute in that case.

If you want to use a SEQUENCE then set the strategy to SEQUENCE ! That way it will use the sequence definition you have defined

Though hibernate-sequence-on-oracle-generatedvaluestrategy-generationtype-auto suggests that this will work, it appears that it is broken for some versions of Hibernate, see HHH-10656 .

Edit: Broken in 5.2.0, unbroken in 5.2.8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM