Skip to main content

hsqldb with GlassFish

2 replies [Last post]
suleimankh
Offline
Joined: 2009-10-02

hi all,, i am new user for glassfish + hslqdb + flash !!

brief definition my problem is
****all the change i do it stay in a cache buffered and not passed to the db (hsqldb.jar) for some reason

Details:

1) i tried to search for the answer of my problem every were i couldn't find the answer.. so just in case if i am opening a thread that already answered i am sorry

2) i build a project that use glassfish as server and hslqdb as standalone (embedded) database using flash builder 4 beta.

3) *** the PROBLEM i am facing is : when i run my program the insertion finish with no error, and then i read it and the select is finished with no error, but the problem after that if i insert and read again.. it will just read the new data.. the old data disappear, and even when i close the program i try to go to \WEB-INF\lib and run my hslqdb.jar.. the table is still empty !!!

i also get this msg
Could not delete C:\glassfishv3-prelude\glassfish\domains\domain1\eclipseApps\test_prjct\WebContent\WEB-INF\lib\test_prjct.jar. May be locked by another process.

in the hibernate cfg url i tried this :
1)jdbc:hsqldb:file:C:\test_prjct\WebContent\WEB-INF\lib\public
2)jdbc:hsqldb:file:C:/test_prjct/WebContent/WEB-INF/lib/public
3)(jdbc:hsqldb:file:WEB-INF/lib/public or jdbc:hsqldb:file:public )---->> in thish i dont get the msg that say :
Could not delete C:\glassfishv3-prelude\glassfish\domains\domain1\eclipseApps\test_prjct\WebContent\WEB-INF\lib\test_prjct.jar. May be locked by another process.

note.. db name is public, and the table name is server

here is my code :

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

org.hsqldb.jdbcDriver

jdbc:hsqldb:file:C:\test_prjct\WebContent\WEB-INF\lib\public

sa
org.hibernate.dialect.HSQLDialect

1
org.hibernate.connection.DriverManagerConnectionProvider

true

create

true
true
0

-----------*----------------------*-----------------------------*-----------------------

here is my mapping
<?xml version="1.0"?>

-----------*----------------------*-----------------------------*-----------------------

here is my model file called Server.java

package model;

/**
* @author Suleiman Khader
*
* Java Class to map to the datbase server Table
*/
public class Server {

private String serverID;
private String serverName;
private String serverIP;

public String getServerID() {
return serverID;
}
public void setServerID(String serverID) {
this.serverID = serverID;
}
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
public String getServerIP() {
return serverIP;
}
public void setServerIP(String serverIP) {
this.serverIP = serverIP;
}

}

-----------*----------------------*-----------------------------*-----------------------

and here is my HibernateUtil.java

package utility;

import org.hibernate.*;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

private static SessionFactory factory;

public static synchronized Session getSession() {
if (factory == null) {
factory = new Configuration().configure().buildSessionFactory();
}
return factory.openSession();
}

public static void setSessionFactory(SessionFactory factory) {
HibernateUtil.factory = factory;
}
}

-----------*----------------------*-----------------------------*-----------------------

here is my servlet

package model;
import java.io.*;
import java.util.Iterator;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import utility.*;

public class HelloWorld extends HttpServlet implements Servlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{

doPost( request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
System.out.println("start 1st");
//FirstExample fex= new FirstExample();
Session session = null;

try{

System.out.println("start");

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =HibernateUtil.getSession();// i used singelton to have one connection to the database

Transaction transaction = session.beginTransaction();

//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
System.out.println("Inserting Record");
System.out.println("Inserting Record");
Server server = new Server();
server.setServerID("123test");
server.setServerIP("ip92929");
server.setServerName("suleiman");
System.out.println(server.getServerID() +" "+server.getServerIP()+" "+server.getServerName());
session.save(server);
transaction.commit();
if (session.isOpen())
{
session.flush();
session.close();
}
session =HibernateUtil.getSession();
String SQL_QUERY ="Select s.serverID,s.serverIP,s.serverName from Server as s";
Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();){
Object[] row = (Object[]) it.next();
System.out.println("ID: " + row[0]);
System.out.println("IP: " + row[1]);
System.out.println("Name: " + row[2]);
}

System.out.println(server.getServerID() +" "+server.getServerIP()+" "+server.getServerName());
System.out.println("Done.....");
if (session.isOpen())
{
session.flush();
session.close();
}
}catch(Exception e){

System.out.println(e.getMessage());
System.out.println("ERROR: failed to load HSQLDB JDBC driver.");
e.printStackTrace();

}finally{
// Actual contact insertion will happen at this step
System.out.println("IN FINALLY !!!");

if (session.isOpen())
{
session.flush();
session.close();
}

}

}

}

please till me were is my mistake... i have store my hsqldb.jar in the \WebContent\WEB-INF\lib directory !!

i think the problem may be in the cfg (in the url) or in the place i stored the hsqldb.jar, but not sure..

here is some of my output :

INFO: exporting generated schema to database
INFO: schema export complete
INFO: Inserting Record
INFO: Inserting Record
INFO: Inserting Record
INFO: 123test ip92929 suleiman
INFO: Hibernate: insert into SERVER (SERVERNAME, SERVERIP, SERVERID) values (?, ?, ?)
INFO: Hibernate: select server0_.SERVERID as col_0_0_, server0_.SERVERIP as col_1_0_, server0_.SERVERNAME as col_2_0_ from SERVER server0_
INFO: ID: 123test
INFO: IP: ip92929
INFO: Name: suleiman
INFO: 123test ip92929 suleiman
INFO: Done.....
INFO: IN FINALLY !!!

when i run it agian i get same output.. which i thought by logic i get
INFO: ID: 123test
INFO: IP: ip92929
INFO: Name: suleiman
twice .. what i get it only once as i run it from the 1st time.. as there is only on record in the database :S

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
suleimankh
Offline
Joined: 2009-10-02

anyone can help??????

suleimankh
Offline
Joined: 2009-10-02

ok i have solved this problem long time ago.. but forgot to upgrade this..

all what i have to do is to move the jar file from my project lib to the server lib.. which make more since since the DB is used ad server layer not project core..