Hi,
I am having difficulties adding a trigger via the
Code:
<database-object>
tag.
As stated in the hibernate documentation, chapter 5.7 (
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html) I try to add a trigger to the database with the following code:
Code:
<hibernate-mapping>
<database-object>
<create>
CREATE OR REPLACE FUNCTION example_function() RETURNS trigger AS $null$
BEGIN
-- insert
IF TG_OP = 'INSERT' THEN
-- insert_task
END IF;
-- delete
IF TG_OP = 'DELETE' THEN
-- delete_task
END IF;
RETURN NULL;
END;
$null$ LANGUAGE plpgsql;
CREATE TRIGGER example_trigger AFTER INSERT OR DELETE
ON example_table FOR EACH ROW
EXECUTE PROCEDURE example_function();
</create>
<drop>DROP TRIGGER example_trigger ON example_table;</drop>
<dialect-scope name="org.hibernate.dialect.PostgreSQLDialect"/>
</database-object>
</hibernate-mapping>
When adding my trigger manually, everything works out fine. I would like to add the trigger automatically, when deploying my schema via hibernate. When trying to add the trigger via the hibernate shema evolution tool, the trigger is not added.
Thanks for any help on this!
Joerg