-->
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: error on creating org.hibernate.cfg.Configuration object
PostPosted: Wed Jan 20, 2010 11:59 am 
Newbie

Joined: Wed Jan 20, 2010 11:48 am
Posts: 1
I am using RAD 6.0 . Doing an application using struts and hibernate

I am using hibernate3.jar from hibernate-distribution-3.3.2.GA-dist.zip(i am newbie to hibernate)

In my Hibernate plugin class ,
I tried creating a configuration object but the application exits when below red coloured statement in init(ActionServlet servlet, ModuleConfig modConfig) is encountered

package com.tutorial.hibernate;

import java.net.URL;
import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.cfg.*;
import org.hibernate.cfg.Configuration;
import org.hibernate.*;


public class HibernatePlugin implements PlugIn {
private Configuration config;
private SessionFactory factory;
private String path = "/hibernate.cfg.xml";
private static Class hpclass = HibernatePlugin.class;
public static final String KEY_NAME = hpclass.getName();
private static Log log = LogFactory.getLog(hpclass);

public void setPath(String path) { this.path = path; }

public void init(ActionServlet servlet, ModuleConfig modConfig) throws ServletException
{
try
{
URL url = HibernatePlugin.class.getResource(path);
config=new Configuration();
config.configure(url);
factory = config.buildSessionFactory();
servlet.getServletContext().setAttribute(KEY_NAME, factory);
}
catch (MappingException e)
{
log.error("Mapping errors:", e);
String messages = e.getMessage();
//for (int i = 0; i < messages.length; i++)
log.error(messages, e);
throw new ServletException();
}
catch (HibernateException e)
{
log.error("Hibernate errors:", e);
String errors = e.getMessage();
//for (int i = 0; i < errors.length; i++)
log.error(errors, e);

throw new ServletException();
}
catch (Exception e)
{
log.error("Hibernate errors:", e);
String errors = e.getMessage();
//for (int i = 0; i < errors.length; i++)
log.error(errors, e);

throw new ServletException();
}
}

public void destroy()
{
try { factory.close(); }
catch (HibernateException e) { log.error("Unable to close factory", e); }
}

}


Kindly help me out it is urgent for me to finish this and move on ..


Top
 Profile  
 
 Post subject: Re: error on creating org.hibernate.cfg.Configuration object
PostPosted: Thu Jan 21, 2010 9:45 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
What is the actual error you're getting?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.