JBoss中关于hibernate not bound, MySqlDS not bound之类的NameNotFoundException

以下内容转自 http://hi.baidu.com/bwgm/blog/item/9f4aaa9920f25a036f068c09.html

在对JBoss中的hibernate, DataSource不太熟悉的使用者中,我们经常碰到如下两个方面关于jndi的问题。

1.
javax.naming.NameNotFoundException: hibernate not bound 或者DataSource javax.naming.NameNotFoundException: MySqlDS not bound之类的NameNotFoundException。

2.
我们通过JNDI能从context中lookup到正确的class,但是返回的对象是null。


这种现象有可能是两个方面的原因引起的:
1. 使用的jndi 和绑定时的jndi name本身不一致,所以找不到对应的class (比较少,但是有)

2. 如果你确保jndi没有使用错误的情况下,在很大可能上就属于如下情形了:
这时候,通常我们的应用程序运行在一个standalone的环境中,也即是我们的client端本身不是运行在JBoss环境中,而是另外一个JVM中。
原因之一,是我们把jndi-name定义成了java:/hibernate/SessionFactory。 可是我们忘了,所有以java:/开头的jndi都只能在同一个JVM中使用。
原因之二,即使我们的jndi并没有以java:/开头(这种情况下返回的通常是null),但是在缺省情况下,出于安全方面的原因,JBoss是把datasoure绑定到java:下的,没有把DataSource share给别的JVM使用。所以我们自然也就查找不到了。
By default, the datasources in JBoss are bound to java: namespace and are not visible outside the server JVM

如果一定想要在另外一个JVM中使用的话,可以在*-ds.xml文件中通过在设置use-java-context为false。

<use-java-context>false</use-java-context>


参考资料:
http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch7.chapt.html
http://www.coderanch.com/t/90286/JBoss/javax-naming-NameNotFoundException
http://community.jboss.org/wiki/ConfigDataSources

Exception 具体描述:
javax.naming.NameNotFoundException: hibernate not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)

转载于:https://www.cnblogs.com/dope/articles/1693637.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值