File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate DS/JNDI in Weblogic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate DS/JNDI in Weblogic" Watch "Hibernate DS/JNDI in Weblogic" New topic
Author

Hibernate DS/JNDI in Weblogic

cempaka melati
Greenhorn

Joined: Sep 29, 2003
Posts: 15
I am trying to use hibernate.cfg.xml.

What works using hibernate.properties is:
I have a startup class and the following works when I hardocde in the program:
private static void doBind() throws Exception {
Properties environment = null;
InitialContext context = null;
try {

environment = new Properties();
environment.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
environment.put("java.naming.provider.url", "t3://localhost:7001");
System.out.println("Constructing an Initial Directory Context object");
context = new InitialContext(environment);

/* Create a single instance of configuration and use it to set hte location of the mapping files.
addClass() assumes that the name of hte mapping file ends with the .hbm.xml extension
and is deployed along with the mapped class file.
If not, use i.e. addResource("monitor/Datum.hbm.xml") */
Configuration cfg = new Configuration();
cfg.setProperty("hibernate.connection.datasource", "TestDS");

_____

When I put the following in the hibernate.cfg.xml:
<session-factory name="java:/hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.datasource">
java:/comp/env/jdbc/TestDS
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>

_____

and change the startup class to:
org.hibernate.SessionFactory factory = cfg.buildSessionFactory();
_____
I get the error:
14:35:25,746 INFO Configuration:917 - processing foreign key constraints
14:35:25,777 INFO NamingHelper:26 - JNDI InitialContext properties:{}
14:35:25,777 FATAL DatasourceConnectionProvider:47 - Could not find datasource:
java:/comp/env/jdbc/TestDSjavax.naming.NameNotFoundException: remaining name: /comp/env/jdbc/TestDS
at weblogic.j2eeclient.SimpleContext.resolve(SimpleContext.java:35)
at weblogic.j2eeclient.SimpleContext.resolve(SimpleContext.java:39)
at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:57)
at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:62)
at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyCo
ntextWrapper.java:45)
at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.j
ava:130)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at org.hibernate.connection.DatasourceConnectionProvider.configure(Datas
ourceConnectionProvider.java:44)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvi
der(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFa
ctory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463
)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1004)
at com.util.common.WLSStartup.doBind(WLSStartup.java:53)
at com.util.common.WLSStartup.startup(WLSStartup.java:27)
at weblogic.t3.srvr.StartupClassService.invokeStartup(StartupClassServic
e.java:177)
at weblogic.t3.srvr.StartupClassService.invokeClass(StartupClassService.
java:158)
at weblogic.t3.srvr.StartupClassService.access$000(StartupClassService.j
ava:36)
at weblogic.t3.srvr.StartupClassService$1.run(StartupClassService.java:1
21)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
121)
at weblogic.t3.srvr.StartupClassService.invokeStartupClass(StartupClassS
ervice.java:116)
at weblogic.t3.srvr.StartupClassService.addDeployment(StartupClassServic
e.java:88)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployment(Depl
oymentTarget.java:337)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployments(Dep
loymentTarget.java:597)
at weblogic.management.mbeans.custom.DeploymentTarget.updateServerDeploy
ments(DeploymentTarget.java:575)
at weblogic.management.mbeans.custom.DeploymentTarget.updateDeployments(
DeploymentTarget.java:241)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at weblogic.management.internal.DynamicMBeanImpl.invokeLocally(DynamicMB
eanImpl.java:754)
at weblogic.management.internal.DynamicMBeanImpl.invoke(DynamicMBeanImpl
.java:733)
at weblogic.management.internal.ConfigurationMBeanImpl.invoke(Configurat
ionMBeanImpl.java:509)
at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
60)
at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
28)
at weblogic.management.internal.RemoteMBeanServerImpl.private_invoke(Rem
oteMBeanServerImpl.java:988)
at weblogic.management.internal.RemoteMBeanServerImpl.invoke(RemoteMBean
ServerImpl.java:946)
at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:954)
at weblogic.management.internal.MBeanProxy.invokeForCachingStub(MBeanPro
xy.java:481)
at weblogic.management.configuration.ServerMBean_Stub.updateDeployments(
ServerMBean_Stub.java:7691)
at weblogic.management.deploy.slave.SlaveDeployer.updateServerDeployment
s(SlaveDeployer.java:1304)
at weblogic.management.deploy.slave.SlaveDeployer.resume(SlaveDeployer.j
ava:347)
at weblogic.management.deploy.DeploymentManagerServerLifeCycleImpl.resum
e(DeploymentManagerServerLifeCycleImpl.java:229)
at weblogic.t3.srvr.SubsystemManager.resume(SubsystemManager.java:131)
at weblogic.t3.srvr.T3Srvr.resume(T3Srvr.java:966)
at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:361)
at weblogic.Server.main(Server.java:32)
startup -- Exception while binding Hibernate Object to Weblogic JNDI
org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(Datas
ourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvi
der(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFa
ctory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463
)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1004)
at com.util.common.WLSStartup.doBind(WLSStartup.java:53)
at com.util.common.WLSStartup.startup(WLSStartup.java:27)
at weblogic.t3.srvr.StartupClassService.invokeStartup(StartupClassServic
e.java:177)
at weblogic.t3.srvr.StartupClassService.invokeClass(StartupClassService.
java:158)
at weblogic.t3.srvr.StartupClassService.access$000(StartupClassService.j
ava:36)
at weblogic.t3.srvr.StartupClassService$1.run(StartupClassService.java:1
21)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
121)
at weblogic.t3.srvr.StartupClassService.invokeStartupClass(StartupClassS
ervice.java:116)
at weblogic.t3.srvr.StartupClassService.addDeployment(StartupClassServic
e.java:88)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployment(Depl
oymentTarget.java:337)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployments(Dep
loymentTarget.java:597)
at weblogic.management.mbeans.custom.DeploymentTarget.updateServerDeploy
ments(DeploymentTarget.java:575)
at weblogic.management.mbeans.custom.DeploymentTarget.updateDeployments(
DeploymentTarget.java:241)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
sachin bellare
Greenhorn

Joined: Feb 13, 2004
Posts: 4
DID YOU SOLVE THIS PROBLEM , I AM HAVING THE SAME ISSUE
CAN YOU EXPLAIN IF YOU DID RESOLVE..

WILL BE GREAT HELP

THANKS
SACHIN

Originally posted by cempaka melati:
I am trying to use hibernate.cfg.xml.

What works using hibernate.properties is:
I have a startup class and the following works when I hardocde in the program:
private static void doBind() throws Exception {
Properties environment = null;
InitialContext context = null;
try {

environment = new Properties();
environment.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
environment.put("java.naming.provider.url", "t3://localhost:7001");
System.out.println("Constructing an Initial Directory Context object");
context = new InitialContext(environment);

/* Create a single instance of configuration and use it to set hte location of the mapping files.
addClass() assumes that the name of hte mapping file ends with the .hbm.xml extension
and is deployed along with the mapped class file.
If not, use i.e. addResource("monitor/Datum.hbm.xml") */
Configuration cfg = new Configuration();
cfg.setProperty("hibernate.connection.datasource", "TestDS");

_____

When I put the following in the hibernate.cfg.xml:
<session-factory name="java:/hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.datasource">
java:/comp/env/jdbc/TestDS
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>

_____

and change the startup class to:
org.hibernate.SessionFactory factory = cfg.buildSessionFactory();
_____
I get the error:
14:35:25,746 INFO Configuration:917 - processing foreign key constraints
14:35:25,777 INFO NamingHelper:26 - JNDI InitialContext properties:{}
14:35:25,777 FATAL DatasourceConnectionProvider:47 - Could not find datasource:
java:/comp/env/jdbc/TestDSjavax.naming.NameNotFoundException: remaining name: /comp/env/jdbc/TestDS
at weblogic.j2eeclient.SimpleContext.resolve(SimpleContext.java:35)
at weblogic.j2eeclient.SimpleContext.resolve(SimpleContext.java:39)
at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:57)
at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:62)
at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyCo
ntextWrapper.java:45)
at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.j
ava:130)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at org.hibernate.connection.DatasourceConnectionProvider.configure(Datas
ourceConnectionProvider.java:44)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvi
der(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFa
ctory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463
)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1004)
at com.util.common.WLSStartup.doBind(WLSStartup.java:53)
at com.util.common.WLSStartup.startup(WLSStartup.java:27)
at weblogic.t3.srvr.StartupClassService.invokeStartup(StartupClassServic
e.java:177)
at weblogic.t3.srvr.StartupClassService.invokeClass(StartupClassService.
java:158)
at weblogic.t3.srvr.StartupClassService.access$000(StartupClassService.j
ava:36)
at weblogic.t3.srvr.StartupClassService$1.run(StartupClassService.java:1
21)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
121)
at weblogic.t3.srvr.StartupClassService.invokeStartupClass(StartupClassS
ervice.java:116)
at weblogic.t3.srvr.StartupClassService.addDeployment(StartupClassServic
e.java:88)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployment(Depl
oymentTarget.java:337)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployments(Dep
loymentTarget.java:597)
at weblogic.management.mbeans.custom.DeploymentTarget.updateServerDeploy
ments(DeploymentTarget.java:575)
at weblogic.management.mbeans.custom.DeploymentTarget.updateDeployments(
DeploymentTarget.java:241)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at weblogic.management.internal.DynamicMBeanImpl.invokeLocally(DynamicMB
eanImpl.java:754)
at weblogic.management.internal.DynamicMBeanImpl.invoke(DynamicMBeanImpl
.java:733)
at weblogic.management.internal.ConfigurationMBeanImpl.invoke(Configurat
ionMBeanImpl.java:509)
at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
60)
at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
28)
at weblogic.management.internal.RemoteMBeanServerImpl.private_invoke(Rem
oteMBeanServerImpl.java:988)
at weblogic.management.internal.RemoteMBeanServerImpl.invoke(RemoteMBean
ServerImpl.java:946)
at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:954)
at weblogic.management.internal.MBeanProxy.invokeForCachingStub(MBeanPro
xy.java:481)
at weblogic.management.configuration.ServerMBean_Stub.updateDeployments(
ServerMBean_Stub.java:7691)
at weblogic.management.deploy.slave.SlaveDeployer.updateServerDeployment
s(SlaveDeployer.java:1304)
at weblogic.management.deploy.slave.SlaveDeployer.resume(SlaveDeployer.j
ava:347)
at weblogic.management.deploy.DeploymentManagerServerLifeCycleImpl.resum
e(DeploymentManagerServerLifeCycleImpl.java:229)
at weblogic.t3.srvr.SubsystemManager.resume(SubsystemManager.java:131)
at weblogic.t3.srvr.T3Srvr.resume(T3Srvr.java:966)
at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:361)
at weblogic.Server.main(Server.java:32)
startup -- Exception while binding Hibernate Object to Weblogic JNDI
org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(Datas
ourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvi
der(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFa
ctory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463
)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1004)
at com.util.common.WLSStartup.doBind(WLSStartup.java:53)
at com.util.common.WLSStartup.startup(WLSStartup.java:27)
at weblogic.t3.srvr.StartupClassService.invokeStartup(StartupClassServic
e.java:177)
at weblogic.t3.srvr.StartupClassService.invokeClass(StartupClassService.
java:158)
at weblogic.t3.srvr.StartupClassService.access$000(StartupClassService.j
ava:36)
at weblogic.t3.srvr.StartupClassService$1.run(StartupClassService.java:1
21)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
121)
at weblogic.t3.srvr.StartupClassService.invokeStartupClass(StartupClassS
ervice.java:116)
at weblogic.t3.srvr.StartupClassService.addDeployment(StartupClassServic
e.java:88)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployment(Depl
oymentTarget.java:337)
at weblogic.management.mbeans.custom.DeploymentTarget.addDeployments(Dep
loymentTarget.java:597)
at weblogic.management.mbeans.custom.DeploymentTarget.updateServerDeploy
ments(DeploymentTarget.java:575)
at weblogic.management.mbeans.custom.DeploymentTarget.updateDeployments(
DeploymentTarget.java:241)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

Solution 1: if you plan to use
<property name="connection.datasource">
java:/comp/env/jdbc/TestDS
</property>
Then you need to mention for your datasource in your web.xml file. I suppose the element is <resource ref>

Solutions 2: use this
<property name="connection.datasource">TestDS </property>

Solution 3 : use this

<property name="jndi.url">t3://localhost:7001</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>

<property name="connection.datasource">TestDS</property>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate DS/JNDI in Weblogic
 
Similar Threads
Hibernate DS/JNDI using Weblogic 8.1
parsing hibernate.cfg.xml using Weblogic
MQ 6.0
Closed Resultset: next
parsing hibernate.cfg.xml with Weblogic