What's the proper way of importing/declaring stored procedure in Hibernate. Currently,in my setup, Hibernate is configured to generate the schema if it doesn't exists, and I have import.sql file to insert referential data. Should I include the source of the procedure into the import.sql file, or there's a better way to do so ?
2 Answers
It is not a good practice to use the hibernate to generate the table. There should be separate scripts created for that. Basically hbm2ddl.auto=create
setting in hibernate is a temporary way to create the tables, but you should not be using it in a standard application. It is even unsafe to have this entry in your configuration settings.Read here for more.
If you have a import.sql
that can generate the shcema and the other DB entities
run it independent of the application. It is always best, not to mix up creating the DB entities (including stored procedures and tables) and using them.
There is none. Stored procedures are out of scope of hibernate. At most you can issue native SQL query , but it will bypass everything. Usually you just take sql script generated by schema export and enhance it manually

- 12,329
- 1
- 30
- 35
-
Yes, but currently, all my integration tests are done in memory, Hibernate is generating the schema for me, it lets me insert ref data, but the only thing I miss to make the in-memory DB complete is the procedure. because everything is happening in real-time, the only way I can think of, is to inject the SQL stored procedure definition as a HQL query. – stdcall Dec 01 '11 at 13:24
-
You can creyate it with help of hibernate native query - it will be passed verbatim to the DB connection (but of course it is not portable across different databases, like hibernate). And you can obtain JDBC connection from session and bypass hibernate completely. – Konstantin Pribluda Dec 01 '11 at 13:44