Cambiando
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
por: (para que muestre el directorio)
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
package test;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class SessionFactory {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocalthreadLocal = new ThreadLocal ();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
private SessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* theSessionFactory
if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
System.out.println("<<<<<<<<<>>>>>>>");
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
SessionFactory.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}
package test;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class ControlHibernate {
private static Logger log = Logger.getLogger(ControlHibernate.class);
public static List getObjetos(String hql) throws HibernateException {
List items = new ArrayList();
Session session = null;
Transaction tx = null;
session = SessionFactory.getSession();
try {
tx = session.beginTransaction();
items = session.createQuery(hql).list();
tx.commit();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
throw e;
} finally {
session.close();
}
return items;
}
public static void guardarObjeto(Object objeto, Integer codigo)
throws HibernateException {
Session session = null;
Transaction tx = null;
session = SessionFactory.getSession();
try {
tx = session.beginTransaction();
// modifica objeto
if ((codigo != null) && (codigo.intValue() != 0)) {
log.info("va a hacer 'merge' de objeto");
session.saveOrUpdate(objeto);
session.flush();
} else { // inserta objeto
log.info("va a hacer 'save' de objeto");
session.save(objeto);
}
tx.commit();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
throw e;
} finally {
session.close();
}
}
}
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
$ cd blazeds_turnkey_3-0-0-544/sampledb/
rene ~/blazeds_turnkey_3-0-0-544/sampledb $ ./startdb.sh
[Server@18a7efd]: [Thread[main,5,main]]: checkRunning(false) entered
[Server@18a7efd]: [Thread[main,5,main]]: checkRunning(false) exited
[Server@18a7efd]: Startup sequence initiated from main() method
[Server@18a7efd]: Loaded properties from [/home/rene/blazeds_turnkey_3-0-0-544/sampledb/server.properties]
[Server@18a7efd]: Initiating startup sequence...
[Server@18a7efd]: Server socket opened successfully in 29 ms.
[Server@18a7efd]: Database [index=0, id=0, db=file:flexdemodb/flexdemodb, alias=flexdemodb] opened sucessfully in 1203 ms.
[Server@18a7efd]: Startup sequence completed in 1233 ms.
[Server@18a7efd]: 2008-04-30 23:14:53.387 HSQLDB server 1.8.0 is online
[Server@18a7efd]: To close normally, connect and execute SHUTDOWN SQL
[Server@18a7efd]: From command line, use [Ctrl]+[C] to abort abruptly
$ cd blazeds_turnkey_3-0-0-544/tomcat/bin/
rene ~/blazeds_turnkey_3-0-0-544/tomcat/bin $ ./startup.sh
Using CATALINA_BASE: /home/rene/blazeds_turnkey_3-0-0-544/tomcat
Using CATALINA_HOME: /home/rene/blazeds_turnkey_3-0-0-544/tomcat
Using CATALINA_TMPDIR: /home/rene/blazeds_turnkey_3-0-0-544/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.6.0_06
$