I'm wondering if it's possible to use JPA or other persistence library with PL/Java together? I mean using JPA persistence for manipulationg database over the special JDBC connection provided by PL/Java in stored Java procedures.
Asked
Active
Viewed 218 times
1 Answers
1
It's possible, but a really bad idea. Most ORMs are pretty memory hungry beasts, and PL/Java spawns one JVM per PostgreSQL backend (connection), so that memory-gobbling will be multiplied per-connection. Worse, many ORMs expect to be able to get numerous connections from a pool and use them freely, but when running in PL/Java with the SPI you only really have one connection since PostgreSQL backends are single-threaded and not thread-safe.
I really don't recommend it.

Craig Ringer
- 307,061
- 76
- 688
- 778
-
I see, thanks. What about lighter ORM like engines? MyBatis for example. – NagyI Jan 26 '13 at 17:16
-
@NagyI If it has low memory footprint and fast startup it might be OK, especially if you use a connection pool like PgBouncer to defray the cost of the expensive backend starts with PL/Java and an ORM. You might still have issues with the ORM not liking being limited to a single connection to the server. It seems unlikely to me that this is a good design to pursue, but I could be wrong and I'd be interested in hearing back if you make it work and get a good result. – Craig Ringer Jan 26 '13 at 22:55