-->
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.  [ 14 posts ] 
Author Message
 Post subject: how to configue JNDI in jboss
PostPosted: Thu Jul 05, 2007 11:35 pm 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
I need to configure JNDI in jboss using hibernate3 . i went the documents and tutorial but not so clear . So can anybody tell me the exact prodecure to configure jndi in boss

thanks in advamce
mnrnjn


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 5:30 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
Can any body help me in this doubt plzzzzzz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 7:59 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
This might help

http://www.hibernate.org/hib_docs/refer ... ation.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 8:30 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
iam getting this execption while looking up in JNDI

Code:
17:58:51,187 INFO  [STDOUT] 17:58:51,187 ERROR [InsuranceHome] Could not locate SessionFactory in JNDI
java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource
   at com.sellermania.hibernate.generated.InsuranceHome.getSessionFactory(InsuranceHome.java:29)
   at com.sellermania.hibernate.generated.InsuranceHome.<init>(InsuranceHome.java:22)
   at com.sellermania.hibernate.generated.InsuranceDao.getdata(InsuranceDao.java:29)
   at test.FirstBeanController.retriveData(FirstBeanController.java:16)
   at test.FirstBean.<init>(FirstBean.java:74)

can anybody help me out in this issue....

thanks
mano[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 8:38 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
Can you post your hibernate.cfg.xml file


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 8:43 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
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>
<session-factory>
      <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hibernate.cglib.use_reflection_optimizer">true</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
       
        <property name="hibernate.connection.pool_size">1</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull</property>
        <property name="hibernate.connection.username">test</property>
         <property name="hibernate.connection.password">test</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
        <property name="hibernate.show_sql">true</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      
      <property name="connection.datasource">java:/MySqlDS</property>
      
      
      <!-- Enable Hibernate's automatic session context management  -->
      <property name="current_session_context_class">thread</property>
      
      <!-- Disable the second-level cache  -->
      <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      
      <!-- Echo all executed SQL to stdout  -->
      <property name="show_sql">true</property>     
      
        <!-- Mapping files   -->
         <mapping resource="com/test/hibernate/generated/insurance.hbm.xml"/>

</session-factory>
</hibernate-configuration>




Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 9:29 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
Try this config file. The SessionFactory is automatically bound to the jndi name and you do not have to do any lookups for the JNDI name.

You simply save your hibernate objects as normal and the transaction is handled by Hibernate.


I think the dialect values are correct for MySQL and the manager_lookup_class is the correct one for JBoss

hope this helps


Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.default_schema">dpcs</property>
        <property name="hibernate.connection.datasource">java:/MySqlDS</property>
      <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
      <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
     
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
      <property name="hibernate.cglib.use_reflection_optimizer">false</property>
       
        <property name="show_sql">true</property>
       <property name="hibernate.format_sql">true</property>
        <property name="hbm2ddl.auto">none</property>
        <property name="cache.use_second_level_cache">false</property>
      <property name="hibernate.current_session_context_class">thread</property>
      <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>

      <mapping resource="com/test/hibernate/generated/insurance.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 9:31 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
Sorry just spotted a typo

remove the line

<property name="hibernate.default_schema">dpcs</property>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 9:40 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
i have doubt in my configuration plz tell if nay thing i mnissed

1.i pasted mysql-ds.xml file in jboss/deploy folder
2. this is my above hibernate file
3.
Code:
Object o  = new InitialContext().lookup("java:MySqlDS");
              System.out.println("><<<<<<<>>>>>>>>>>>>>>>>>>>>>" + o.toString());
s = (SessionFactory)o;
   


this is my mysql-ds.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: mysql-ds.xml 41016 2006-02-07 14:23:00Z acoliver $ -->
<!--  Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->

<datasources>
  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://localhost/test</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>test</user-name>
    <password>test</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <!-- should only be used on drivers after 3.22.1 with "ping" support
    <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
    -->
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
     
  </local-tx-datasource>
 
</datasources>



can you verify the process and tell me if any wrong
I get the same error ...
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 9:50 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
I'm not familiar with MySQL at all and am not sure if you have setup your datasource properly. Maybe there is a MySQL forum somewhere you can check it on.

As for your code, you do not need to perform the jndi lookup.

Get your SessionFactory like below and then create begin your transaction:

Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.getOpenSession();

or

Session session = sessionFactory.getCurrentSession();

then

Transaction tx = session.beginTransaction();

session.save(objectToSave);

tx.commit();




Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 9:55 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
Thanks for your reply . The code you have mentiod above is the normal way of getting session factory.Then what is the use of configuring JNDI in jboss
and modifying hibernate.cfg.xml.So what is the procedure of looking form jndi to get the session factory... Can you explain me in detail plz iam bit confused..


thanks
mano


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 10:16 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
Hi,

When we use Hibernate we don't need to perform a JNDI lookup to get the datasource. Hibernate looks after that.

You setup your datasource in JBoss, set the username password and url etc and give it a JNDI.

Then in the Hibernate.cfg.xml we tell Hibernate what datasource to use and what transaction manager etc to use.

Then when Hibernate saves any data it uses the datasource that you have defined.

Has this helped or confused you more ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 10:32 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
thanks for ur reply . Ya Iam a bit clear now thanks for explanation. But i trieda as you said but i get error saying session factory is null

Code:
[Configuration] Configured SessionFactory: null
in jboss

Can you help me on this issue..

thanks ,
mano


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 1:51 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
Can any body help me in this issue .Can any body post some sample how to configure


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