-->
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: JNDI bound SessionFactory !!!
PostPosted: Sun Jul 13, 2008 12:10 pm 
Newbie

Joined: Thu Feb 14, 2008 1:47 am
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.5

Mapping documents:
<hibernate-configuration>

<session-factory>

<!-- <property name="hibernate.connection.datasource">java:MySqlDS</property> -->
<property name="hibernate.session_factory_name">java:Mydatabase</property>
<property name="hibernate.jndi.url"></property>
<property name="hibernate.jndi.class"></property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>

<property name="show_sql">true</property>
<property name="format_sql">true</property>

<!-- Show and print nice SQL on stdout. -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<!-- List of XML Mapping files -->
<mapping resource="contact.hbm.xml"/>
<!-- <mapping resource="address.hbm.xml"/> -->

</session-factory>

</hibernate-configuration>



Code between sessionFactory.openSession() and session.close():
Session session = null;

try{
System.out.println("Before Session Factory Configuration. !!!");

SessionFactory sf = new Configuration().configure().buildSessionFactory();


jndiContext = new InitialContext();

sf = (SessionFactory)jndiContext.lookup("java:MySqlDS");


session = sf.openSession();

System.out.println("After Session Factory Configuration. !!!");



}catch(Exception e){
e.printStackTrace();
}finally{
session.flush();
session.close();
}




Full stack trace of any exception that occurs:

Name and version of the database you are using: MySQL 5.0.45

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi All,
1) Please help me in configuring JNDI bound SessionFactory in Hibernate. I am using MySQL database and JBoss 4.2.2 app. server. Please help me I am not getting help/clue from anywhere. I have searched the net also. Anyhelp will be highly appreciated. Thanks in advance. I have tried writing a simple program but it dosen't work.

2) Is configuring a datasource and configuring JNDI bound SessionFactory one and the same thing. If No then how to configure a datasource using the same above configuration.

Please Help !!!
Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 10:25 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
A similar post was answered at hibernate.org:

Well, it's a great idea to bind a Hibernate Session to you JNDI (Java Naming and Directory Interface) server. This way, rather than having to maintain the Session yourself, the JNDI server will, and that resource can then be accessed by any resource that has access and the rights to do a JNDI lookup.

Here you can see it in a sample hibernate.cfg.xml file.

This was loosely stolen from Chapter 3 of the Hibernate documentation. Look it up for more details:

Free Hibernate Documentation for People to Use to Learn Things About Hibernate

code:



<?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>

<!-- a SessionFactory instance listed as /jndi/name -->

<session-factory
name="java:hibernate/SessionFactory">

<!-- properties -->
<property name="connection.datasource">java:/comp/env/jdbc/MyDB</property>
<property name="dialect">org.hibernate.dialect.SCJASQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>

<!-- mapping files -->


<!-- cache settings -->


</session-factory>

</hibernate-configuration>

_________________
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  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 1:04 pm 
Newbie

Joined: Thu Feb 14, 2008 1:47 am
Posts: 9
It says could not find datasource exception !!! :(


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.