How to use a sequence in sleep mode as a property in an XML mapping

How to use sequence in Hibernate XML mappings?

The documentation mentions an element <generator>. However, I want the sequence to be a column instead of an identifier.

+3
source share
2 answers

I know that when using Hibernate with Oracle, the identifier in the mapping file is defined as:

<id name="id" column="item_id">
    <generator class="sequence">
        <param name="sequence">NAME_OF_YOUR_SEQUENCE</param>
    </generator>
</id>

You can also specify the generator class as "native", which is convenient if you then switch to automatically increasing RDMS, such as MySQL. After that, the sequence bit is ignored in MySQL.

Edit: . , hibernate id. , , , .

+6

Oracle, Hibernate , ( , ).

, , oracle , hibernate xml , :

   <property name="hibernateProperties">
        <props>
        ...
            <prop key="hibernate.jdbc.use_get_generated_keys">true</prop>
        ...
        </props>

     <generator class="sequence-identity">
        <param name="sequence">SEQ_NAME</param>
    </generator>
0

Source: https://habr.com/ru/post/1526542/


All Articles