-->
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.  [ 1 post ] 
Author Message
 Post subject: Session is disconnected when running tests
PostPosted: Sun May 09, 2004 12:33 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
hi all,
in my app i have created a Persistence layer which abstract the way i persist objects (i use both castor and hibernate).
When running the persistence layer within a J2EE app (and in an application server) everything works perfectly fine.'
When, however, i am running my tests 'off-line' in Maven, whenever i call a PersistenceManager operation, i got an exception that the Session is disconnected.

My wild guess is because the SessionFactory should be bound to a JNDI name...
however, when i run tests NOT using PersistenceManager, session works just fine.
Can anyone tell me what is wrong?
thanx in advance and regards
marco

here is my PersistenceManager code...


/**
* Constructor
*/
HibernatePersistenceManager() throws Exception{
_log.debug("Creating HibernatePM..");
initHibernate();
}

/**
* Initializes Hibernate with the config file found at
* <code>configFilePath</code>.
*/
private void initHibernate() throws Exception {
Configuration configuration = null;
URL configFileURL = null;
ServletContext context = null;

try {
configFileURL = HibernatePersistenceManager.class.getResource(_configFilePath);
_log.debug("Initializing Hibernate from "
+ _configFilePath + "...");


configuration = (new Configuration()).configure(configFileURL);
_factory = configuration.buildSessionFactory();

_log.debug("Simple Test....creatingp ersistent expense.....");
} catch (Throwable t) {
_log.error("Exception while initializing Hibernate.");
_log.error("Rethrowing exception...", t);
throw (new Exception(t));
}
}


public void insert(Entry data) throws PersistenceException {
try {
Session s = openSession();
//HibernateEntry entry = (HibernateEntry)data;
Transaction t = s.beginTransaction();
s.save(data);
t.commit();
s.close();
} catch(Exception e) {
_log.error("Exception in creating CastorEntry\n" + e);
throw new PersistenceException(e);
}
}

public void update(Entry data) throws PersistenceException{
try {
Session s = openSession();
HibernateEntry entry = (HibernateEntry)data;
Transaction t = s.beginTransaction();
s.saveOrUpdate(entry);
t.commit();
s.close();
} catch(Exception e) {
_log.error("Exception in creating CastorEntry\n" + e);
throw new PersistenceException(e);
}


}

public void delete(Entry data) throws PersistenceException{
try {
Session s = openSession();
HibernateEntry entry = (HibernateEntry)data;
Transaction t = s.beginTransaction();
s.delete(entry);
t.commit();
s.close();
} catch(Exception e) {
_log.error("Exception in creating CastorEntry\n" + e);
throw new PersistenceException(e);
}
}

public Collection query(String query, Object[] paramValues) throws PersistenceException{

Collection returnResults = new Vector();
Query entryQuery;

List results = new ArrayList();
try {
Session s = openSession();
_log.debug("----HibPersMgr. getting query...");
entryQuery = s.getNamedQuery(query);
if(paramValues != null) {
for(int i=0; i < paramValues.length; i++){
entryQuery.setParameter(i,paramValues[i]);
}
}
_log.debug("---- obtained query" + query);
results = entryQuery.list();
_log.debug("---- query finished. got:" + results.size() + " elements!");
// To be done

} catch(Exception e) {
_log.error("Exception in querying HibernateEntry\n" + e);
throw new PersistenceException(e);
}

return results;

}


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

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.