-->
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.  [ 9 posts ] 
Author Message
 Post subject: [jboss]dumb question
PostPosted: Thu Jul 08, 2004 1:21 pm 
Newbie

Joined: Thu Jul 08, 2004 1:10 pm
Posts: 11
Hello, good afternoon.

I followed the tutorial here
http://www.hibernate.org/66.html

and one question still remains: how do I instantiate a SessionFactory in my code?

I failed a few times, but here goes my last try:

Code:
InitialContext ic = new InitialContext();
      SessionFactory sessFactory = ( SessionFactory ) ic.lookup( "java:/hibernate/HibernateFactory" );
      Session sess = sessFactory.openSession();


My jboss datasource works fine, and I deployed the ear, that contains the sar, jars, war etc, without getting any error messages.

Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 1:24 pm 
Newbie

Joined: Thu Jul 08, 2004 1:10 pm
Posts: 11
Forgot to post the exceptions:

Code:
javax.naming.NameNotFoundException: hibernate not bound


And another one telling me that it couldn


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 5:49 pm 
Newbie

Joined: Tue Jun 01, 2004 8:06 pm
Posts: 9
Location: Hamilton, Ontario, Canada
Make sure the hibernate.cfg.xml file is in your classpath for your application.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 1:33 am 
Newbie

Joined: Thu Jul 08, 2004 1:10 pm
Posts: 11
oh, even with all the other configuration files, hibernate.cfg.xml is still necessary?

thanks for replying :D


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 9:51 am 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
No the hibernate.cfg.xml is not needed any more.
If you get an error that the cfg file is missing then you should make sure that you are not using something like sessionFactoryMap.get(configFileName).
If you are using the same code like the webpage you are pointing to then you should take a look at the web-console of jboss, there you should see the bounded hibernate mbean and it's jndi name. May be a type error inside jboss-service.xml.

regards

Olaf


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 12:43 pm 
Newbie

Joined: Thu Jul 08, 2004 1:10 pm
Posts: 11
Kaneda, you are superestimating my intelligence hehe my problem is *very* basic: in the tutorial, there is no code example showing how to get a reference to a SessionFactory object.

Could you please post it for me?

Thanks a lot :D


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 3:30 am 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession()
throws NamingException, HibernateException {
Session s = (Session) session.get();
if (s == null) {
SessionFactory sf = (SessionFactory) new InitialContext().lookup("java:/HibernateTicketsystem");
s = sf.openSession();
session.set(s);
}
return s;
}

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

Here we go. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 3:32 am 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
BTW Exchange "java:/HibernateTicketsystem" with the JNDI name being defined in your jboss-service.xml.

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 1:25 pm 
Newbie

Joined: Thu Jul 08, 2004 1:10 pm
Posts: 11
Thanks a *LOT* Kaneda :D :D :D

This could be inserted in the tutorial, don


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