-->
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: Cannot open connection
PostPosted: Fri Mar 03, 2006 2:46 pm 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
Tomcat 5.5 on XP
hibernate3.jar

I have read the book, and this is my first time getting rolling programatically. I just need to get this simple step complete, then I believe I can roll. Is there a way to find out exactly what is failing? Aside from just a Cannot open connection?



I have created a cfg type configuration and placed it under WEB-INF/classes (classpth)
Here it is:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">XXXXX</property>
<property name="connection.password">XX</property>
<property name="connection.url">jdbc:oracle:thin:@XXXX.com:1521</property>
<property name="show_sql">true</property>
<property name="">true</property>
<mapping resource="/com/xxxxxx/xx.hbm.xml" />
</session-factory>
</hibernate-configuration>


2) I created a simple Configuration like so in a singleton class.
Configuration cfg = new Configuration();
cfg.configure("/hibernate.cfg");
sessionFactory = cfg.buildSessionFactory();

Nothing blows up until I make this call, and then I get a "Cannot open connection" there at 2 exception.

Session session = ConnectionFactory.getInstance().getSession();

try
{
Query query =
session.createQuery(
"from myclass myclass");
return query.list();

}
catch (HibernateException e)
{
System.err.println("2 Hibernate Exception" + e.getMessage());


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 3:08 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
what is ConnectionFactory...?

Here is the basic steps, using a properties file... which can be modified cfg.configure() to load the cfg.xml file instead (see this other thread for info on cfg.xml vs. properties loading:
http://forum.hibernate.org/viewtopic.php?t=956099&highlight=hibernate+properties

Code:
Configuration cfg = new Configuration();
Properties p=new Properties();
try {
    p.load(new FileInputStream(new File("hibernate.properties")));
} catch (IOException e) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);

    System.err.println(e.getMessage());
    e.printStackTrace(pw);
    System.err.println(baos.toString());
    e.printStackTrace();
    System.exit(-1);
}
cfg.buildSettings(p);

cfg.addClass(test.proc.AccountSources.class);

SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = null;
session = sessionFactory.openSession();


Hope this helps some...

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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.