Results 1 to 2 of 2

Thread: Retrieve Connection from entitymanager

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    20

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Simply use JdbcTemplate with a ConnectionCallback that gives you access to the current connection.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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