-->
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: Could not locate SessionFactory in JNDI -> I am a newbie!
PostPosted: Thu Nov 10, 2005 11:52 am 
Newbie

Joined: Thu Nov 10, 2005 11:43 am
Posts: 2
Hi,

I'm new to Hibernate. ;)

I have a JBoss running and a HypersonicDB as Server Engine running.

I set up a small phonebook-Table, which was is accessable through Hibernate Tools.

So I finished everything as it mentioned in the tutorial...

Now I generated a DAO-File to test the generated files...

This is my CFG:

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.cglib.use_reflection_optimizer">true</property>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:hsql://dbserver:1701</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
        <mapping resource="de/siller/test/PhonebookHibernate.hbm.xml" />
    </session-factory>
</hibernate-configuration>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="de.siller.test.PhonebookHibernate" table="PHONEBOOK_HIBERNATE" schema="PUBLIC">
        <id name="userid" type="string">
            <column name="USERID" length="10" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="NAME" length="30" />
        </property>
        <property name="number" type="string">
            <column name="NUMBER" length="20" />
        </property>
    </class>
</hibernate-mapping>



In my testAPP i have the following code.. which may be wrong, cause it is to easy... ;)


Code:
PhonebookHibernateHome phh = new PhonebookHibernateHome();
      PhonebookHibernate ph = new PhonebookHibernate();

      ph.setName("Test");
      ph.setNumber("2193042");
      ph.setUserid("esgf");
      phh.persist(ph);


Then I get the following Exception...

Code:
Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
   at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
   at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source).....


What's wrong?

Hope you can help me.

Greetings,

James


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 12:57 pm 
Beginner
Beginner

Joined: Tue Jun 14, 2005 12:14 pm
Posts: 37
To register the SessionFactory in JNDI, all you need to do in your cfg.xml file is to include the JNDI name where you want it to go:

<?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 name="java:/hibernate/SessionFactory">
...


Hope that helps.

Liem


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 5:51 pm 
Newbie

Joined: Thu Nov 10, 2005 11:43 am
Posts: 2
Hi,

I haven't tried it yet, but I still have a question... Isn't right, that I have to deploy my app to register the JNDI???

The only Connection I have, is the connection to my database-Server.

Guess my app/the config needs to know where my application server runs, right?

I'm a little bit confused now... :)

Gretz

James


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.