-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem setting up session
PostPosted: Wed Feb 09, 2005 7:04 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
hi,

im very new to hibernate. ive been following the tutorial on the site but have come accross a problem when trying to run a simple session.
ive copied the code but ran into a problem with the log.

this is the original code

Code:
private static Log log = LogFactory.getLog(HibernateUtil.class);


im given the options of:

LogFactory (org.apache.commons.logging)
Log4jFactory(org.apache.commons.logging.impl

i changed it to:
Log4jFactory(org.apache.commons.logging.impl

then im asked for the Log to change to:

Log (org.apache.commons.logging
Logger (org.apache.log4j)
LogLog (org.apache.log4j.helper)

i changed it to:
Logger (org.apache.log4j)


the line ends up being:
rivate static Logger log = (Logger) Log4jFactory.getLog(HibernateUtil.class);

instead of:
private static Log log = LogFactory.getLog(HibernateUtil.class);


this is my main class

Code:

package net.sf.hibernate.examples.quickstart;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;

public class TestHibernate
{
    public static void main(String args[]) throws HibernateException
    {
       Session session = HibernateUtil.currentSession();
       Transaction tx = session.beginTransaction();
       
       Cat tom = new Cat();
       tom.setName("tom");
       tom.setSex('F');
       tom.setWeight(7.4f);
       session.save(tom);
       tx.commit();
       HibernateUtil.closeSession();
    }
}



the error occurs at:
Session session = HibernateUtil.currentSession();


my error is this:
Code:
java.lang.ExceptionInInitializerError
   at net.sf.hibernate.examples.quickstart.TestHibernate.main(TestHibernate.java:12)
Caused by: java.lang.ClassCastException
   at net.sf.hibernate.examples.quickstart.HibernateUtil.<clinit>(HibernateUtil.java:11)
   ... 1 more

Exception in thread "main"


can anyone see what im doing wrong

thanks for the help


Top
 Profile  
 
 Post subject: log4j
PostPosted: Thu Feb 10, 2005 4:18 pm 
Newbie

Joined: Tue Dec 14, 2004 2:57 pm
Posts: 12
This is a logging issue, and if you are really serious about programming with Java, you will want to get to know log4j. Please have a look at the documentation for log4j.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 5:52 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
cheers for that. i give that a look


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.