2

Is it possible to define a trigger in a postgres DB that can call some Java function?

(I believe the above is possible in Oracle, but want to know if it for postgres).

So if this is possible, does this mean that the Java function would be called for every client application that is connected to the DB which of course has the function defined?

Thnx.

2 Answers 2

1

There is the PL/Java add-on:

PL/Java is a free add-on module that brings Java™ Stored Procedures, Triggers, and Functions to the PostgreSQL™ backend via the standard JDBC interface.

I haven't used it so I can't comment on how good it is.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. Do you happen to know if there are any tutorials/sample-code for this? This would really help.
@Larry: There are some examples in the source download under src/java/examples that might help.
thanx, this looks it would be helpful.
PL/Java is a dead project. No release in over 2 years and the mailing list seems dead too.
@Gili: Thanks for the update. I'm actually more interested in PL/v8 these days, haven't touched Java for quite some time.
1

I don't know if it can fit your needs, but if you're using Hibernate to communicate with the DB, you can use Hibernate event listeners as triggers ( http://docs.jboss.org/hibernate/core/3.3/reference/en/html/events.html , http://docs.jboss.org/hibernate/core/3.3/api/org/hibernate/event/package-summary.html). That way it would work whatever the DB is (given you use standard SQL queries or HQL queries in the triggers)

1 Comment

I would generally recommend against using Hibernate event listeners as triggers: any decently designed non trivial database scheme is likely to have some cascades set up to guarantee consistency of the data. These cascades will not trigger Hibernate event listeners. Additionally when you step outside the boundaries of Hibernate for performance reasons (which you'll also likely do in any non trivial application) the events will not be triggered as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.