-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate session factory jndi name not bound
PostPosted: Thu Apr 24, 2008 8:11 am 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:03 pm
Posts: 21
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.x

Mapping documents:
<?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="session_factory_name">
java:/hibernate/TrackingSessionFactory
</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.JBossTransactionManagerLookup
</property>
<property name="connection.datasource">java:/trackingDS</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.JBossTransactionManagerLookup
</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="show_sql">true</property>
<mapping
resource="com/eon/tracking/instance/DefaultTracking.hbm.xml" />
</session-factory>
</hibernate-configuration>

and DefaultTracking.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.eon.tracking.instance.DefaultTracking"
table="events">
<meta attribute="class-description">
Represents a events track in the event_tracking database.

</meta>
<id name="id" type="int" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="increment" />
</id>
<property name="sessionId" column="sessionId"/>
<property name="channelName" column="channelName" />
<property name="vehicleId" column="vehicleId" />
<property name="timeDateStamp" column="timeDateStamp" />
<property name="inspectionId" column="inspectionId" />
<property name="regMark" column="regMark" />
</class>

</hibernate-mapping>


and Datasource mapping is as below.

<local-tx-datasource>
<jndi-name>trackingDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/event_tracking</connection-url>
<!-- The driver class -->
<driver-class>com.mysql.jdbc.Driver</driver-class>
<!-- The login and password -->
<user-name>root</user-name>
<password>password</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->
<min-pool-size>2</min-pool-size>
<!-- The maximum connections in a pool/sub-pool -->
<max-pool-size>50</max-pool-size>
<idle-timeout-minutes>10</idle-timeout-minutes>
<prepared-statement-cache-size>32</prepared-statement-cache-size>



Code to get the session factory

public class HibernateUtil {
private static Logger LOGGER = Logger.getLogger(HibernateUtil.class);
private static Context jndiContext;

static {
try {
LOGGER.debug(" Loading configuration .....");
Configuration config = new Configuration().configure(
"com/eon/tracking/persistence/hibernate/config/tracking-hibernate.cfg.xml");
LOGGER.debug(" Configuration loaded .. " + config);
jndiContext = new InitialContext();
} catch (Throwable ex) {
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
}

/**
* Returns the SessionFactory using.
*
* @return SessionFactory
*/
public static SessionFactory getSessionFactory(String sfName)
throws PersistenceException {
SessionFactory sessions = null;

try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" Looking up for session factory name : " +
sfName);
}

sessions = (SessionFactory) jndiContext.lookup(sfName);
} catch (NamingException ex) {
ex.printStackTrace();
throw new PersistenceException(ex);
}

return sessions;
}
}


:


Full stack trace of any exception that occurs:

13:06:52,093 DEBUG [HibernateUtil] Loading configuration .....
13:06:52,296 INFO [Environment] Hibernate 3.2.3
13:06:52,312 INFO [Environment] hibernate.properties not found
13:06:52,312 INFO [Environment] Bytecode provider name : javassist
13:06:52,312 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
13:06:52,359 INFO [Configuration] configuring from resource: com/eon/tracking/persistence/hibernate/config/tracking-hibernate.cfg.xml
13:06:52,359 INFO [Configuration] Configuration resource: com/eon/tracking/persistence/hibernate/config/tracking-hibernate.cfg.xml
13:06:52,421 INFO [Configuration] Reading mappings from resource : com/eon/tracking/instance/DefaultTracking.hbm.xml
13:06:52,500 INFO [HbmBinder] Mapping class: com.eon.tracking.instance.DefaultTracking -> events
13:06:52,531 INFO [Configuration] Configured SessionFactory: null
13:06:52,531 DEBUG [HibernateUtil] Configuration loaded .. org.hibernate.cfg.Configuration@a6343d
13:06:52,531 DEBUG [HibernateUtil] Looking up for session factory name : java:/hibernate/TrackingSessionFactory
13:06:52,531 ERROR [STDERR] javax.naming.NameNotFoundException: hibernate not bound
13:06:52,546 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
13:06:52,546 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
13:06:52,562 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
13:06:52,562 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
13:06:52,562 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
13:06:52,562 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
13:06:52,578 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:392)
13:06:52,578 ERROR [STDERR] at com.eon.tracking.persistence.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:59)
13:06:52,593 ERROR [STDERR] at com.eon.tracking.service.instance.DefaultTrackingDataRetrievalService.getTrackingDataForAVehicle(DefaultTrackingDataRetrievalService.java:44)
13:06:52,593 ERROR [STDERR] at com.eon.pricing.spring.service.instance.PriceDecisionService.getPageVisits(PriceDecisionService.java:993)
13:06:52,593 ERROR [STDERR] at com.eon.pricing.spring.controller.PricingDecisionController.showPricingDetail(PricingDecisionController.java:105)
13:06:52,593 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)



Name and version of the database you are using:MySQL

The generated SQL (show_sql=true): yes, but no query generated

Debug level Hibernate log excerpt:DEBUG

Could you any one plase shade some lights what I might be doing wrong here?

Thanks & REgards,
Irfan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 5:54 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Why are you bothering with JNDI when you're accessing your SF through HibernateUtil? Just store it as a static... If you want a container managed SF, use the MBean. Or skip all this nonsense and just use EJB3. All you need is a persistence.xml!

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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