[英]Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasource
I am getting this error when getting sessionfactory from jboss JNDI and here is my source code.I have tried several times with many modifications but it has been not solved. 我从jboss JNDI获取sessionfactory时遇到此错误,这是我的源代码。我已经尝试了几次,做了很多修改,但尚未解决。 Thanks in advance. 提前致谢。
which is placed in jboss default deploy folder. 它放置在jboss的默认部署文件夹中。
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/NeuraDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/neurahmis</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>admin</user-name>
<password>admin@123</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>1000</max-pool-size>
<exception-sorter-class- name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
</local-tx-datasource>
</datasources>
Added in web.xml for datasource 在web.xml中添加了数据源
<resource-ref>
<description>Database connection resource</description>
<res-ref-name>Neura</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Added in jboss-web.xml for jndi 在jboss-web.xml中为jndi添加了
<jboss-web>
<context-root>/neurads</context-root>
<resource-ref>
<res-ref-name>Neura</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:jdbc/NeuraDS</jndi-name>
</resource-ref>
</jboss-web>
These are my hibernate properties. 这些是我的休眠属性。
<property name="hibernate.connection.datasource">java:/jdbc/NeuraDs</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
To obtain the session factory 获取会话工厂
sessionFactory=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
Not sure why you need to put entry in web.xml
and jobss-web.xml
. 不知道为什么需要将条目放入web.xml
和jobss-web.xml
。 mysql-ds.xml
should be sufficient to binding a datasource to JNDI tree . mysql-ds.xml
应该足以将数据源绑定到JNDI tree 。
In the file hibernate.cfg.xml
, you mentioned the datasource as java:/jdbc/NeuraDs
, Can you correct it to jdbc/NeuraDs
and then try. 在文件hibernate.cfg.xml
,您提到的数据源为java:/jdbc/NeuraDs
,可以将其更正为jdbc/NeuraDs
然后尝试。 This is how I used it in my project and its working. 这就是我在项目及其工作中使用它的方式。 The JNDI name should be identical to what you mentioned in mysql-ds.xml
. JNDI名称应与您在mysql-ds.xml
提到的名称相同。
Please make sure that you check the start up logs to see any error related to this configuration. 请确保您检查启动日志以查看与此配置相关的任何错误。
It has something to do with reading the connection creation properties. 它与读取连接创建属性有关。 When you directly give connection properties through system property it works. 当您通过系统属性直接提供连接属性时,它将起作用。 Something related to basic hibernate set up looks wrong. 与基本的休眠设置有关的东西看起来不对。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.