views:

980

answers:

2

Hi,

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.

+1  A: 

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

Chris Serra
A: 

Chris, thanks. I was thinking along that line, I'm implementing a subclass of PersistentIdentifierGenerator, but maybe IdentifierGenerator is enough. So the next question is: how to call the Oracle function? Can Spring or Hibernate help here?

OliBlogger