-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: HSQLDB and JPA
PostPosted: Sat Feb 16, 2008 10:48 pm 
Newbie

Joined: Sat Feb 16, 2008 10:44 pm
Posts: 2
Hello guys, excuse me, my English is not very good, I hope you understand me, but I've a dude, and I'd like you resolve it.

I'm working with JPA and hsqldb.
My URL connection is jdbc:hsqldb:file:/home/luis/Desktop/Proyecto/SAETest/db/saedb.
I created the DB with SQuierreL SQL Client Program, using DDL (Data Definition Language), this program generated 3 files :
a)saedb.log,
b)saedb.properties,
c)saedb.script
This last file has all DDL to create the database and it is like a backup for myDB. I show you an example of it:

CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE MEMORY TABLE USUARIO(NOMBREUSUARIO CHAR(20) NOT NULL PRIMARY KEY,CONTRASENIA CHAR(12) NOT NULL,IDPERSONA INTEGER NOT NULL,PERFIL INTEGER NOT NULL)
CREATE USER SA PASSWORD ""...
GRANT DBA TO SA...
SET WRITE_DELAY 20...
SET SCHEMA PUBLIC...
INSERT INTO LOCAL VALUES(1,'Hilton Colon',300,'Norte','Guayaquil','Ecuador')...
INSERT INTO LOCAL VALUES(2,'Salon Prescidencial Hotel Oro Verde',150,'Centro','Guayaquil','Ecuador').....

I created "Entity classes from Database", and Persistence.xml(2 Persistence Units) using Netbeans IDE and connecting it with myDB through URL Connection.

I've two Persistence's Providers: OPenJPA(Apache), and TopLink(Oracle), not used Hibernate, becose is not was requirement in my University Project , excuse me please:

<persistence-unit name="PUOpenJPA" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>businesslogic.Evento</class>
<class>businesslogic.Local</class>
<class>businesslogic.Persona</class>
<class>businesslogic.Usuario</class>
<properties>
<property name="openjpa.ConnectionPassword" value=""/>
<property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver"/>
<property name="openjpa.ConnectionUserName" value="sa"/>
<property name="openjpa.ConnectionURL" value="jdbc:hsqldb:file:/home/luis/Desktop/Proyecto/SAETest/db/saedb"/>
<property name="openjpa.jdbc.Schema" value="PUBLIC"/>
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
</properties>
</persistence-unit>
<persistence-unit name="PUTopLink" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<class>businesslogic.Evento</class>
<class>businesslogic.Local</class>
<class>businesslogic.Persona</class>
<class>businesslogic.Personaevento</class>
<class>businesslogic.Usuario</class>
<properties>
<property name="toplink.jdbc.user" value="sa"/>
<property name="toplink.jdbc.password" value=""/>
<property name="toplink.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
</properties>
</persistence-unit>

Now, I've a class which creates 2 objects a)EntityManagerFactory, and b)EntityManager :

...
...
Query query;
Map propiedades = new HashMap();
propiedades.put(TopLinkProperties.JDBC_URL, "jdbc:hsqldb:file:"+System.getProperty("user.dir")+"/db/saedb");

EntityManagerFactory emf = Persistence.createEntityManagerFactory("PUTopLink",propiedades);
EntityManager em = emf.createEntityManager();

em.getTransaction().begin();

local = new Local();
local.setCapacidad(20); local.setCiudad("Guayaquil");
local.setDireccion("Av. No recuerdo cerca de no recuerdo"); local.setIdlocal(5);
local.setLugar("C.C. San Marino"); local.setPais("Ecuador");

em.persist(local);

em.getTransaction().commit();


query = em.createQuery("select count(l) from Local l");
ultimo = Integer.parseInt(query.getSingleResult().toString());

System.out.println("Ultimo Ingresado :"+ultimo);


em.close();

At first sight, everything looks good, but this is being only saved in the memory. So If I close the EntityManager all data will lose and it won't save in myDB or in the saedb.script file.

The question is: What can I do to save data in myDB or saedb.script?, or Should I change the "saedb.properties" file?.

The "saedb.properties" file:

#HSQL Database Engine 1.8.0.9
#Sat Feb 16 15:20:00 ECT 2008
hsqldb.script_format=0
runtime.gc_interval=0
sql.enforce_strict_size=false
hsqldb.cache_size_scale=8
readonly=false
hsqldb.nio_data_file=true
hsqldb.cache_scale=14
version=1.8.0
hsqldb.default_table_type=memory
hsqldb.cache_file_scale=1
hsqldb.log_size=200
modified=yes
hsqldb.cache_version=1.7.0
hsqldb.original_version=1.8.0
hsqldb.compatible_version=1.8.0



Help me please!!!,
Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 24, 2008 2:45 pm 
Newbie

Joined: Sat May 24, 2008 2:41 pm
Posts: 1
I am having the exact same problem.

I have tried appending shutdown=true at the end of connection url.
I saw this on some other site.

It still not working.

Any help? anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:45 am 
Newbie

Joined: Fri Aug 04, 2006 11:27 am
Posts: 2
have you try to change
Code:
hsqldb.default_table_type=memory

into
Code:
hsqldb.default_table_type=cached

in the saedb.properties file


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 5:03 am 
Newbie

Joined: Fri Aug 04, 2006 11:27 am
Posts: 2
Forget my previous post.

I have the same problem, and i found the solution :
add
Code:
<property name="connection.shutdown">true</property>


the hibernate.cfg.xml config file.

and in your ObjectManager

Code:
Session session = null;
    try
    {
      session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
     
      User user = new User();
      user.setFirstName("olivier");
      user.setLastName("chabrol");
      session.save(user);

      session.getTransaction().commit();
      System.out.println(user);
    }
    catch (HibernateException e)
    {
      if (null != session.getTransaction())
        session.getTransaction().rollback();
      throw e;
    }
    finally
    {
      HibernateUtil.getSessionFactory().close();
    }


dont forget the HibernateUtil.getSessionFactory().close();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 8:44 am 
Beginner
Beginner

Joined: Tue Aug 29, 2006 8:08 am
Posts: 34
Ok,and besides commiting properly last transactions ¿does any body have
the problem of the forever remaining lck file?

I mean, my app. creates a lock file (*.lck) as i indicate with the property
hsqldb.lock_file to true (I use the embedded mode, NOt standalone). Problem
is that in Linux it al works perfectly but in my beloved Windoze the .lck
file never dissapears so in subsequent executions I must remove it my self manually.

I have a post with lots of responses from hsqldb people (http://sourceforge.net/forum/forum.php? ... m_id=73674), tried it all and
still the f#!&!! file lives forever.

I have the connection.shutdown to true from hibernate (programatically as i do not use cfg.xml) i also set the shutdown=true at the hsqldb url ......... i'll try to smash a hammer right in the middle of my cpu and that shall be the end of it all .......


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.