-->
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.  [ 8 posts ] 
Author Message
 Post subject: DataSource not found error
PostPosted: Sat Nov 08, 2003 12:46 am 
Newbie

Joined: Sat Nov 08, 2003 12:39 am
Posts: 7
Hi,

While trying to play with hibernate for first time, I'm trying to run one
of the example.
I have dataSource mapped in app-server with a JNDI name and I'am able to access that DataSource if I run a lookup (JNDI) for it but when
try to do following I'm getting DataSource not found error.

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


Anybody any ideas as what I'm missing?

Thanks.

ERROR/EXCEPTION:

[INFO] Environment - -Hibernate 2.0.3
[INFO] Environment - -hibernate.properties not found
[INFO] Environment - -using CGLIB reflection optimizer
[INFO] Environment - -JVM proxy support: true
[INFO] Configuration - -Configuration resource: /hibernate.cfg.xml
[INFO] Configuration - -Mapping resource: com/ibm/hibernate_article/Employee.hbm.xml
[INFO] Binder - -Mapping class: com.ibm.hibernate_article.Employee -> employee
[INFO] Configuration - -Mapping resource: com/ibm/hibernate_article/Department.hbm.xml
[INFO] Binder - -Mapping class: com.ibm.hibernate_article.Department -> department
[INFO] Configuration - -Configured SessionFactory: HibernateFactory
[INFO] Configuration - -processing one-to-many association mappings
[INFO] Configuration - -processing foreign key constraints
[INFO] SessionFactoryImpl - -building session factory
[INFO] Dialect - -Using dialect: net.sf.hibernate.dialect.OracleDialect
[INFO] NamingHelper - -JNDI InitialContext properties:{weblogic.jndi.replicateBindings=false}
[FATAL] DatasourceConnectionProvider - -Could not find datasource: jdbc/DataSource/WBS <javax.naming.NoInitialContextExc
eption: Need to specify class name in environment or system property, or as an applet parameter, or in an application re
source file: java.naming.factory.initial>javax.naming.NoInitialContextException: Need to specify class name in environm
ent or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:638)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:241)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:278)
at javax.naming.InitialContext.lookup(InitialContext.java:345)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:45)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83
)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:153)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
at Test.main(Test.java:12)

Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system p
roperty, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:638)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:241)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:278)
at javax.naming.InitialContext.lookup(InitialContext.java:345)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:45)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83
)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:153)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
at Test.main(Test.java:12)
rethrown as net.sf.hibernate.HibernateException: Could not find datasource: 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 net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:49)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83
)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:153)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
at Test.main(Test.java:12)


Top
 Profile  
 
 Post subject: hibernate.cfg.xml
PostPosted: Sat Nov 08, 2003 1:15 am 
Newbie

Joined: Sat Nov 08, 2003 12:39 am
Posts: 7
I do have hibernate.cfg.xml file so I'm assuming I do NOT need to have hibernate.properties in my classpath?

Here is my XML look like:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<!-- Generated file - Do not edit! -->

<hibernate-configuration>

<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="HibernateFactory">

<!-- properties -->
<property name="connection.datasource">jdbc/DataSource/WBS</property>
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">false</property>
<property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="hibernate.jndi.weblogic.jndi.replicateBindings">false</property>

<!-- mapping files -->
<mapping resource="com/ibm/hibernate_article/Employee.hbm.xml"/>
<mapping resource="com/ibm/hibernate_article/Department.hbm.xml"/>
</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 08, 2003 2:17 am 
Newbie

Joined: Tue Nov 04, 2003 4:48 am
Posts: 12
Location: Iran
What is your application server?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 08, 2003 2:31 am 
Newbie

Joined: Sat Nov 08, 2003 12:39 am
Posts: 7
wblogic 7.x


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 08, 2003 2:38 am 
Newbie

Joined: Sat Nov 08, 2003 12:39 am
Posts: 7
I've just noticed something in the doc (http://www.hibernate.org/34.html)

...WebLogic Server's JNDI implementation is known to be incompatible with Hibernate. Questions regarding this issue should be directed to BEA, since it it due to their lack of support for a fairly non-exotic part of the JNDI spec...


IS THAT REALLY TRUE? Any details?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 12:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Supposedly it is for binding Hibernate to JNDI, but not for Hibernate getting things out of JNDI.

If you look at the stack trace, you see that the problem has to do with InitialContext being unable to load an initial context factory. Typically this is done by setting the following:

System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); // or whatever they call it in 7x
System.setProperty(javax.naming.Context.PROVIDER_URL, "t3://yourhost");


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 12:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
<property name="jta.UserTransaction">java:comp/UserTransaction</property>

Also, weblogic binds the default UserTransaction under javax/transaction/UserTransaction; so this element should become:
<property name="jta.UserTransaction">javax/transaction/UserTransaction</property>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 12:17 am 
Newbie

Joined: Sat Nov 08, 2003 12:39 am
Posts: 7
Yeah, I actually passed that point and added information related to JNDI url etc in my mapping file and that changed the output exception to some marshalling parameter exception and this situation matches with the argument made about the inability of Weblogic JNDI to work with Hibernate. I've also noticed some work around in a FAQ for that but still need to give it a try. http://www.hibernate.org/74.html

My purpose was to test out hibernate and see how the lazy loading
works. So, ended up using straight up JDBC connection and things started to roll.

Thank you all!


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