Hibernate version:3.0.2
Name and version of the database you are using:Oracle 8
Hello.
considering a simple table USER_FUNCTION containing a few fields and a primary key of type number named FCT_ID.
Also, considering this table has the following trigger script to automatically set the FCT_ID:
Code:
CREATE OR REPLACE TRIGGER user_function_id_trig
BEFORE INSERT ON USER_FUNCTION
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
declare
-- local variables here
begin
select user_function_seq.nextval into :new.FCT_ID from dual;
end user_function_id_trig;
/
in php, the sql used to insert data and fetch the id looks like this (may be a bit wrong as am writing this from memory but you get the idea):
Code:
"INSERT into USER_FUNCTION (FCT_NAME_FR,FCT_NAME_NL) value (:a,:b) returning FCT_ID into :fct_id";
How do i configure the generator part in the hibernate mapping so the primary key is fetched from database after the insert? I saw there is a select generator which does fetch id using a select but it requests that one of the other persistent object's properties is unique. (like the SocialSecurityNumber in docs).
There is also a sequence generator but it won't work because at insert time, the trigger will change the value set by hibernate for FCT_ID.
So what do i put there?:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="be.rmi.intranet.db.users" default-lazy="true">
<class name="be.rmi.intranet.db.users.Function" table="USER_FUNCTION" lazy="true">
<id name="id">
<column name="fct_id" not-null="true" unique="true" sql-type="NUMBER"/>
<generator class="***SO WHAT?**">
??? ???????????????????? ????
</generator>
</id>
<property name="nameFr" column="FCT_NAME_FR" type="string" not-null="false"/>
<property name="nameNl" column="FCT_NAME_NL" type="string" not-null="false"/>
<many-to-one name="manager" column="manager" not-null="false"/>
<set name="backups" table="USER_FCT_BACKUP" sort="be.rmi.intranet.util.PrioritizableComparator">
<key column="FCT_ID"/>
<one-to-many class="be.rmi.intranet.db.users.FunctionBackup"/>
</set>
</class>
</hibernate-mapping>
Thanks