[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Getting a database connection with EntityManagerImpl

Hi Antonio,

Take a look at the org.eclipse.persistence.jpa.JpaHelper class. It is built specifically to expose the non-JPA-standard-based functionality. The getServerSession(emf) method is likely the method that would be most useful to you.

With the server session you can get a hold of alot of the underlying data structures.

-Tom

Antonio Goncalves wrote:
Hi,

I'm using DbUnit with EclipseLink for unit testing. I sent an email to the DbUnit mailing list wondering if there was a easier way to get a database connection using the information included in a persistence.xml file. Julien Tabouret replied with a hint on the method EntityManager.getDelegate(). His example (see below) uses Hibernate.

With EclipseLink the EntityManager.getDelegate() method returns an org.eclipse.persistence.internal.jpa.EntityManagerImpl object. I can't find any documentation about this class (http://www.eclipse.org/eclipselink/api/1.0.1/index.html).

Do you know how I can get a database connection (to give to dbunit) with the EntityManagerImpl object ?

Thanks,
Antonio

---------- Forwarded message ----------
From: *julien tabouret* <julien.tabouret@xxxxxxxxx <mailto:julien.tabouret@xxxxxxxxx>>
Date: 2008/9/17
Subject: Re: [dbunit-user] Persistence.xml
To: dbunit-user@xxxxxxxxxxxxxxxxxxxxx <mailto:dbunit-user@xxxxxxxxxxxxxxxxxxxxx>



Hello,

If you have a /persistence.xml/ file, I assume that you're using an /EntityManager/. If so, the */getDelegate()/* method could help you since it retrieves the underlying object for the /EntityManager/.

For example, if your O/R mapping provinder is Hibernate, you will get an /org.hibernate.impl.SessionImpl/. Then the /connection()/ method will gives you the JDBC connection required by dbunit.

Hope it can help.
--
Julien

2008/9/17 Antonio Goncalves <antonio.mailing@xxxxxxxxx <mailto:antonio.mailing@xxxxxxxxx>>

    Hi,

    I was wondering if DBUnit has some facilities to integrate a
    persistence.xml file. In the persistence.xml file file there is
    already the JDBC Driver, the connection URL to the database, login,
    pwd... everthing needed to connect to a DB. What I'm doing at the
    moment is duplicating this information into my code sych as :

    protected IDatabaseConnection getConnection() throws Exception {
            Class driverClass =
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            Connection jdbcConnection =
    DriverManager.getConnection("jdbc:derby:myDB.sql;create=true",
    "APP", "APP");
            return new DatabaseConnection(jdbcConnection);
        }

    it would be nice just to have new
    DatabaseConnection("persistence.xml"). Because the properties change
    depending on the prodiver, we could also have something like w
    DatabaseConnection("persistence.xml", ORACLE).

    Any ideas ?

    --
    Antonio Goncalves (antonio.goncalves@xxxxxxxxx
    <mailto:antonio.goncalves@xxxxxxxxx>)
    Software architect

    Paris JUG leader : www.parisjug.org <http://www.parisjug.org>
    Web site : www.antoniogoncalves.org <http://www.antoniogoncalves.org>
    Blog: jroller.com/agoncal <http://jroller.com/agoncal>
    LinkedIn: www.linkedin.com/in/agoncal
    <http://www.linkedin.com/in/agoncal>

    -------------------------------------------------------------------------
    This SF.Net email is sponsored by the Moblin Your Move Developer's
    challenge
    Build the coolest Linux based applications with Moblin SDK & win
    great prizes
    Grand prize is a trip for two to an Open Source event anywhere in
    the world
    http://moblin-contest.org/redirect.php?banner_id=100&url=/
    <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
    _______________________________________________
    dbunit-user mailing list
    dbunit-user@xxxxxxxxxxxxxxxxxxxxx
    <mailto:dbunit-user@xxxxxxxxxxxxxxxxxxxxx>
    https://lists.sourceforge.net/lists/listinfo/dbunit-user


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/ <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
_______________________________________________
dbunit-user mailing list
dbunit-user@xxxxxxxxxxxxxxxxxxxxx <mailto:dbunit-user@xxxxxxxxxxxxxxxxxxxxx>
https://lists.sourceforge.net/lists/listinfo/dbunit-user





--
--
Antonio Goncalves (antonio.goncalves@xxxxxxxxx <mailto:antonio.goncalves@xxxxxxxxx>)
Software architect


Paris JUG leader : www.parisjug.org <http://www.parisjug.org>
Web site : www.antoniogoncalves.org <http://www.antoniogoncalves.org>
Blog: jroller.com/agoncal <http://jroller.com/agoncal>
LinkedIn: www.linkedin.com/in/agoncal <http://www.linkedin.com/in/agoncal>


------------------------------------------------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users