OliCoder
OliCoder

Reputation: 1399

How to use a Oracle function for the ID in Hibernate

Until recently we used Oracle sequences to generate the IDs of a table. This is now changed, a new ID is now calculated by an Oracle function. Which means that my application needs a change to adept to the new situation. The application is a Spring/Hibernate webApp, which access the Oracle database. This was configured in an hbm.xml as follows:

<class name="TableHib" table="TABLENAME" >
    <id name="Id" type="java.lang.Long">
        <column name="ID" precision="22" scale="0" />
        <generator class="sequence">
            <param name="sequence">SEQTABLE</param>
        </generator>
    </id>

Question is of course: what is a solution to use the result of Oracle function for the new value of the ID?

Help is much appreciated, thanks in advance.

Upvotes: 0

Views: 1832

Answers (1)

Chris Serra
Chris Serra

Reputation: 13546

Can you write a Java class that can fetch the value of the Oracle function? If so, you should be able to define that Java class as your <generator class>

Edit: To call an Oracle function from Java, see if this works for you: Call Java Oracle Functions From Java program and see the Java CallableStatement API

Upvotes: 1

Related Questions