users@glassfish.java.net

problem connecting to database using JPA

From: <glassfish_at_javadesktop.org>
Date: Thu, 18 Oct 2007 13:30:08 PDT

I'm trying to execute following two lines of code WITHOUT previous connection to the database.

EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);
EntityManager em = emf.createEntityManager();

I am able to successfully pass first line. The EntityManagerFactory is created. On the second line I'm getting
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.Error Code: -4499

In the persistence.xml under persistenceUnitName there is all the information required for connection:
<properties>
<property name="toplink.jdbc.user" value="mike"/>
<property name="toplink.jdbc.password" value="mike"/>
<property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/MyTest"/>
<property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
</properties>

I'm using NetBeans 5.5 with internal Tomcat 5.5.17 and Derby as a database.
How can I obtain database connection from java code using JPA?
Please help.
[Message sent by forum member 'javmike' (javmike)]

http://forums.java.net/jive/thread.jspa?messageID=241037