我们正在将我们的服务器从 Jboss 5.1 升级到 Jboss 7.1 Final。但并非所有服务器都会立即迁移到新技术。
我正在升级 Hibernate 4.0 和 Jboss 7.1 上的第一台服务器。但无法通过 JNDI 连接到位于其他 Jboss 服务器(5.1)上的数据源。
数据源 (*-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>
休眠.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]
请告诉我我错过了什么。如果我以正确的方式做这件事,我也想要一个指导。