我们正在将服务器从Jboss 5.1升级到Jboss 7.1 Final。但并非所有服务器都会立即转向新技术。
我正在升级Hibernate 4.0和Jboss 7.1上的第一台服务器。但是无法通过JNDI连接到位于Other Jboss Server(5.1)上的Datasource。
数据源(* -ds.xml)
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/wc-mysql</jndi-name>
<connection-url>jdbc:mysql://XXX:3306/wellclub</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>myclub</user-name>
<password>myclub</password>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<!-- The minimum connections in a pool/sub-pool.
Pools are lazily constructed on first use -->
<min-pool-size>50</min-pool-size>
<!-- The maximum connections in a pool/sub-pool -->
<max-pool-size>200</max-pool-size>
<!-- setting java context as Global so outsider can also use it. -->
<use-java-context>false</use-java-context>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
的hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.datasource">jdbc/wc-mysql</property>
<property name="hibernate.jndi.url">jnp://jndi.wellclub.me:1099</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.jta.UserTransaction">UserTransaction</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
</session-factory>
</hibernate-configuration>
在Hibernate Utility类中,我将SessionFactory作为
启动Configuration configuration = new Configuration().configure();
// Add all the Annotated classes here...
ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
builder.applySettings(configuration.getProperties());
serviceRegistry = builder.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry); <== Error
例外:
03:28:01,820 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/core]] (MSC service thread 1-2) Exception sending context initialized event to listener instance of class com.wellclub.service.WCStartupService: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [jdbc/wc-mysql]
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2273) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2269) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1738) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at com.wellclub.model.util.ParentHibernateUtil.initiateSessionFactory(ParentHibernateUtil.java:131) [wc-model-2.3.0.jar:]
at com.wellclub.model.util.HibernateUtil.initiateSessionFactory(HibernateUtil.java:32) [classes:]
at com.wellclub.service.WCStartupService.contextInitialized(WCStartupService.java:44) [classes:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
Caused by: javax.naming.NameNotFoundException: jdbc/wc-mysql -- service jboss.naming.context.java.jdbc.wc-mysql
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
at javax.naming.InitialContext.lookup(InitialContext.java:396) [rt.jar:1.6.0_26]
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
... 24 more
错误行
org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [jdbc/wc-mysql]
请告诉我我错过了什么。如果我以正确的方式这样做,我也想要一个指导。
答案 0 :(得分:0)
我注意到可能是原因的两件事,
1. <use-java-context>false</use-java-context> - set it to true
2. hibernate.jndi.class is different for Jboss 4 and 7 atleast.
那些事情可能会成功。
但我强烈建议你在JBoss 7上创建本地数据源。
答案 1 :(得分:0)
可能你应该尝试查找像这样的数据源jndi名称
<property name="hibernate.connection.datasource">java:jboss/datasources/jdbc/wc-mysql</property>
在Jboss服务器管理控制台的配置文件选项卡下
连接器中的- &gt; DataSources部分列出了数据源的JNDI名称