Announcement Announcement Module
Collapse
No announcement yet.
Retrieve Connection from entitymanager Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieve Connection from entitymanager

    Hi All,
    I'm using Spring 3, Hibernate & JPA 1 for my web app & mysql as the DB server
    I want to retrieve the native Connection object from the entitymanager. How can I do this?

    After much research on this, I tried with this code
    Code:
    org.hibernate.Session oSession = (org.hibernate.Session)((this.oJPATemplate.getEntityManager()).getDelegate());
    oSession.connection();
    But this is giving NPE (session being null, I guess) & more over .connection() method is deprecated.

    The reason i need connection object is that i must be able to access the temporary tables.
    If i do a
    Code:
    datasource.getConnection()
    then a new connection is established and hence i cannot access the temporary table

    Thank you

  • #2
    Simply use JdbcTemplate with a ConnectionCallback that gives you access to the current connection.

    Comment

    Working...
    X