-->
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: Problem wiht HIBERNATE ANd Axis. Cannot get Session...
PostPosted: Fri Sep 17, 2004 10:03 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Hibernate version: 2.1

Mapping documents:

Code between sessionFactory.openSession() and session.close():

public class HibernatePersistenceManager implements PersistenceManager {

private LogWrapper _log = new LogWrapper(this.getClass().getName());
/**
* the path to the xml configuration file. the path should start with a
* '/' character and be relative to the root of the class path.
* (DEFAULT: "/hibernate.cfg.xml")
*/
private String _configFilePath = "/hibernate.cfg.xml";

/**
* Hibernate Session Factory
*/
private SessionFactory _factory = null;

/**
* ThreadLocal Session variable
*/
private static final ThreadLocal session = new ThreadLocal();

/**
* Constructor
*/
public 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();
if(_factory == null)
System.err.println("SESSIONFACTORY IS NULL IN CONSTRUCTOR!");
else
System.err.println("SESSIONFACTORY IS OK IN CONSTRUCTOR!");
_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 {
Transaction t = null;
Session s = null;
try {
_log.error("INSERTING ENTRY...:" + data.getDescription());
s = openSession();
_log.error("after opening entry...");
t = s.beginTransaction();
_log.error("after starting transaction...");
s.save(data);
_log.error("after saving entry...");
t.commit ();
_log.error("ENTRY INSERTED!...");
} catch(Exception e) {
_log.error("Exception in creating HibernateEntry\n" + e);
try {
if(t != null)
t.rollback();
} catch(Exception ex) {
_log.error("Failed to rollback transaction!\n" + ex);
}
throw new PersistenceException(e);
} finally {
try {
closeSession();
} catch(Exception ex) {
throw new PersistenceException("Failed to close Hibernate session!\n" + ex);
}
}
}
}

Session openSession() throws Exception {
Session s = (Session)session.get();
if(s== null) {
s = _factory.openSession();
session.set(s);
}
return s;
}

void closeSession() throws Exception {
Session s = (Session)session.get();
session.set(null);
if(s != null)
s.close();
}







Hello all,
i have written a Webservice using Axis and Hibernate.
when i run my client, it looks like the WS (which is using the class HibernatePersistenceManager, code above) is not inserting anything.
As a matter of fact, by inserting logging, it looks like an exception is raised at the line

s = openSession();


My WS does not implement ServiceLifeCycle......

anyone can help? according to the init()method, the SessionFactory is NOT null...so the problem is only when the mehtod openSession() is called..

anyone can help?

thanx in advance and regards
marco


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.