How do you set the schema name for sequences during deployment when using JPA?

For security reasons, our oracle db objects usually belong to a different scheme than the registered user. For instance. the tables are in xx_core, and the user we are registering with is xx_app_yy. In my persistence.xml, I define an orm file to specify a schema name during deployment, for example:   <mapping-file>xx_schema_orm.xml</mapping-file>

Then in xx_schema_orm.xml I can define the owner-schema object, for example:

<persistence-unit-metadata>
  <persistence-unit-defaults>
    <schema>xx_core</schema>
  </persistence-unit-defaults>
</persistence-unit-metadata>

This works fine for tables, but I cannot find the equivalent for sequences. It tries to use a sequence without a schema name, and then gets an exception:

2010-10-14 03: 04: 05,423: DEBUG could not get next sequence value [select xx_SEQ.nextval from dual] - org.hibernate.util.JDBCExceptionReporter
java.sql.SQLException: ORA-02289: sequence does not exist

    at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:145)

I tried to set the schema name as part of the sequence name for the generator in xx_schema_orm.xml, but could not get it to work, for example:

<sequence-generator name="xx_SEQ_GEN"
sequence-name="xx_core.xx_SEQ"/>

Workarounds I can try:

  • Create a SYNONYM database for sequences in the user schema.
  • Stop using sequences and use another way of generating identifiers.
+5
source share
2 answers

In JPA 2.0:

  • @SequenceGenerator sequence-generator schema ( catalog).
  • schema .

JPA 1.0.

schema, ( ). JPA 2.0:

12.2.1.1

schema , , , , , .

schema schema entity-mappings ; schema, Table SecondaryTable schema Table secondary-table, entity; schema TableGenerator table-generator ; , SequenceGenerator sequence-generator ; schema JoinTable join-table ; , CollectionTable collection-table .

JPA 1.0:

10.1.1.1

schema , .

schema schema entity-mappings ; schema Table SecondaryTable Table secondary-table entity; schema TableGenerator table-generator ; schema JoinTable join-table .

, , :

  • JPA 2.0, , schema ~ ~
  • TableGenerator, JPA 1.0 ~ ~
  • , ( ).

  • JPA 1.0
    • 9.1.37 " Sequence"
    • 10.1.1.1 ""
    • 12.2.2.5 " "
  • JPA 2.0
    • 11.1.44 " Sequence"
    • 12.2.1.1 ""
    • 12.2.2.5 " "
+4

, , , , ?

0

All Articles