-->
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.  [ 2 posts ] 
Author Message
 Post subject: HSQLDB and JPA
PostPosted: Sat Feb 16, 2008 10:50 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) :

<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: Mon Feb 18, 2008 5:43 pm 
Newbie

Joined: Fri Sep 26, 2003 1:50 pm
Posts: 9
Hello Sharam,

Have a look at this post:

http://forum.hibernate.org/viewtopic.php?p=2254037#2254037

/Ross.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.