日期:2014-05-19  浏览次数:20721 次

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 Session