首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

hibernate weblogic JDNI 配置找不到DataSource,该如何处理

2012-06-06 
hibernate weblogic JDNI 配置找不到DataSourceorg.hibernate.HibernateException: Could not find dataso

hibernate weblogic JDNI 配置找不到DataSource

org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:84)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:459)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
at meePay.bank.services.dao.HibernateUtil.rebuildSessionFactory(HibernateUtil.java:78)
at meePay.bank.services.dao.HibernateUtil.getCurrentSession(HibernateUtil.java:61)
at meePay.bank.services.client.Hibernate_test.main(Hibernate_test.java:19)
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'myDatasource'. Resolved '' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'myDatasource'. Resolved '']; remaining name 'myDatasource'
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at weblogic.jndi.internal.ServerNamingNode_1033_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:405)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:393)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
... 10 more
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'myDatasource'. Resolved ''
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
....


这个是出现的错误,数据库用的Oracle的,连接Test通过,JNDI名字是"myDatasource"


<hibernate-configuration>
<session-factory name="">
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.Oracle9Driver</property>
<property name="connection.datasource">myDatasource</property>
<property name="jndi.url">t3://localhost:7001/</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>

Hibernate配置文件 


try {
// configuration.configure(configFile);
configuration.configure(HibernateUtil.class.getResource("/hibernate.cfg.xml"));
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
//TODO: write log file logger.error(e);
}
使用时构造Factory就出错,这代码是我从网络上Copy来的.我在Weblogic配置就没成功过.

Weblogic 10.3.3 Hibernate 3.6
谁帮帮我,我找过好多 CLASSPATH, weblogic 8.1.5 (到处 Copy).....


[解决办法]
试试这个Configuration t = new Configuration ();
SessionFactory factory = t.configure().buildSessionFactory();
Session session = factory.openSession();

热点排行