Hi There,
I am trying to create a JPA application using Eclipse, MySQL v. 5.1.4 and
Glassfish v2.1 Java EE 5.
I configured the persistence.xml file using eclipselink but it doesn't seems
to work. I am getting the following error while trying to deploy it in the
server:
[exec] CLI171 Command deploydir failed : Deploying application in domain
failed; Deployment ErrorException [EclipseLink-4002] (Eclipse Persistence
Services - 1.1.2.v20090612-r4475):
org.eclipse.persistence.exceptions.DatabaseException
[exec] Internal Exception: java.sql.SQLException: Connection could not
be allocated because: java.net.ConnectException : Error connecting to server
localhost on port 1527 with message Connection refused.
The complete error log
--------------------------
Buildfile:
/Users/venkibalasubramanian/Software/workspace/.metadata/.plugins/org.eclipse.jst.server.generic.core/serverdef/sunappsrv-ant.xml
deploy.j2ee.web:resourcesfile.check:replace.module.name.space:
[delete] Deleting:
/Users/venkibalasubramanian/Software/workspace/.metadata/.plugins/org.eclipse.jst.server.generic.core/serverdef/fooFile2.properties
tools:
addresources:
replace.module.name.space:
[delete] Deleting:
/Users/venkibalasubramanian/Software/workspace/.metadata/.plugins/org.eclipse.jst.server.generic.core/serverdef/fooFile2.properties
tools:
deploydir:
[exec] CLI171 Command deploydir failed : Deploying application in domain
failed; Deployment ErrorException [EclipseLink-4002] (Eclipse Persistence
Services - 1.1.2.v20090612-r4475):
org.eclipse.persistence.exceptions.DatabaseException
[exec] Internal Exception: java.sql.SQLException: Connection could not
be allocated because: java.net.ConnectException : Error connecting to server
localhost on port 1527 with message Connection refused.
[exec] Error Code: 0 -- Exception [EclipseLink-4002] (Eclipse
Persistence Services - 1.1.2.v20090612-r4475):
org.eclipse.persistence.exceptions.DatabaseException
[exec] Internal Exception: java.sql.SQLException: Connection could not
be allocated because: java.net.ConnectException : Error connecting to server
localhost on port 1527 with message Connection refused.
[exec] Error Code: 0
BUILD FAILED
/Users/venkibalasubramanian/Software/workspace/.metadata/.plugins/org.eclipse.jst.server.generic.core/serverdef/sunappsrv-ant.xml:221:
The following error occurred while executing this line:
/Users/venkibalasubramanian/Software/workspace/.metadata/.plugins/org.eclipse.jst.server.generic.core/serverdef/sunappsrv-ant.xml:131:
exec returned: 1
Total time: 3 seconds
-------------------------------------------------
I used the following files for creating the JPA application:
Persistence.xml , index.jsp , Register. java and RegisterDetails.java
Persistence.xml
---------------------
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="
http://java.sun.com/xml/ns/persistence"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="NaraProject"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.nara.project.RegisterDetails</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.jdbc.url"
value="jdbc:mysql://localhost:3306/test"/>
<property name="eclipselink.jdbc.user" value="root"/>
<property name="eclipselink.jdbc.password"
value="root"/>
<property name="eclipselink.jdbc.driver"
value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.ddl-generation"
value="drop-and-create-tables" />
<property
name="eclipselink.ddl-generation.output-mode" value="both" />
<property name="eclipselink.logging.level"
value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
RegisterDetails.java (Entity File)
-----------------------------------
package org.nara.project;
import java.io.Serializable;
import javax.persistence.*;
/**
* Entity implementation class for Entity: RegisterDetails
*
*/
@Entity
@Table (name="register")
public class RegisterDetails implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="fname")
private String first_name ;
@Column(name="sname")
private String sur_name;
private static final long serialVersionUID = 1L;
public RegisterDetails() {
super();
}
public String getFirstName() {
return first_name;
}
public void setFirstName(String fname) {
first_name = fname;
}
public String getSurName() {
return sur_name;
}
public void setSurName(String sname) {
sur_name = sname;
}
}
Register.java (Servelet File)
------------------------------
package org.nara.system;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
// import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
/**
* Servlet implementation class Register
*/
public class Register extends HttpServlet {
private static final long serialVersionUID = 1L;
@PersistenceUnit
private EntityManagerFactory emf ;
public int i = 1 ;
public Register() {
super();
}
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
}
protected void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
//Obtain data from the form
String fname = req.getParameter("firstname");
String sname = req.getParameter("surname");
try {
if (fname.length()==0) {
out.println("First Name required");
out.println(" index.jsp <br>Back ");
return;}
else if (sname.length()==0){
out.println("Surname required");
out.println(" index.jsp <br>Back ");
return;}
//end the method
storeRegisterVal(fname, sname);
out.println(fname + " " + sname + " is now registered
in the database.");
out.println("<p><form method=\"POST\"
action=index.jsp>");
out.println("<p><input type=\"submit\" value=\"Home\"
>");
out.println("</form>");
}
catch (Exception ex){
out.println("Error 1: " + ex.getMessage());
return; //end of method
}
finally {
out.close(); //close stream
}
}
public void storeRegisterVal(String f_name, String s_name) {
emf = Persistence.createEntityManagerFactory("Axle8Project") ;
EntityManager em = emf.createEntityManager();
EntityTransaction userTransaction = em.getTransaction();
userTransaction.begin();
RegisterDetails regValues = new RegisterDetails();
regValues.setFirstName(f_name);
regValues.setSurName(s_name) ;
em.persist(regValues);
userTransaction.commit();
em.close();
emf.close();
}
}
I even created the jdbc datasource in glassfish by creating connection pool
in glassfish and tested all the datasource but eclipselink is trying to
connect to (the default Derby) database on localhost on port 1527.
Your help is much appreciated !
Thanks
Venki
--
View this message in context: http://old.nabble.com/Use-Oracle-with-Glassfis2-u2-for-JPA-tp20563623p27335609.html
Sent from the java.net - glassfish users mailing list archive at Nabble.com.