Results 1 to 6 of 6

Thread: hibernate session init

  1. #1

    Default hibernate session init

    Hi!

    Is there a way to execute some code right after a hibernate session is created? My problem is that i have to call a stored procedure (one-time per session) before any create/update statement is executed. Else my create/update statements won't work.

    Thanks in advance for any help!

  2. #2
    Join Date
    Aug 2004
    Location
    Berne, Switzerland
    Posts
    42

    Default

    Can't help you about Hibernate, but if you're working against an Oracle database, why don't you use an ON LOGON system trigger, which will always fire after a session is created.
    Will of course also only fire once for a pooled connection.
    Guido Schmutz
    Principal Consultant, Trivadis Switzerland
    Email: guido.schmutz AT trivadis.com

  3. #3

    Default

    Thanks !

    Think i'll give it a try but our db admins won't be happy :(

    Although I hoped I could manage it within spring/hibernate.
    Experimented a bit with hibernate's Interceptor but this seems to be the wrong approach. Maybe anyone knows something similar which could help me.

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Maybe it's unsuitable, but we add seed data by a simple bean that implements InitializingBean.

  5. #5

    Default

    Tried it, but the problem is that the session gets closed
    between the bean's initialization and the save/update call.

    But it was a good hint anyway. I think it could sovle some other problems ...

    thanks

  6. #6
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default Re: hibernate session init

    Quote Originally Posted by nyname00
    Hi!

    Is there a way to execute some code right after a hibernate session is created? My problem is that i have to call a stored procedure (one-time per session) before any create/update statement is executed. Else my create/update statements won't work.

    Thanks in advance for any help!
    You should be able to wrap the SessionFactory you are using in a spring interceptor (take a look at the spring manual) which when the session factory is asked to create a new session, does create the session, then either uses it or spring jdbc to call your stored proc...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. OpenSessionInView and portlet support
    By garpinc2 in forum Web Flow
    Replies: 31
    Last Post: Apr 9th, 2010, 11:12 AM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Replies: 2
    Last Post: May 24th, 2005, 06:51 PM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Replies: 9
    Last Post: Sep 25th, 2004, 12:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •