简体   繁体   English

初始SessionFactory创建失败.org.hibernate.HibernateException:找不到数据源

[英]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. 提前致谢。

mysql-ds mysql-ds

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>

web.xml web.xml

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>

jboss-web.xml jboss-web.xml

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>

hibernate.cfg.xml hibernate.cfg.xml

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>

HibernateUtil.java HibernateUtil.java

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.xmljobss-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.

相关问题 初始SessionFactory创建失败.org.hibernate.HibernateException:缺少列 - Initial SessionFactory creation failed.org.hibernate.HibernateException: Missing column 收到以下错误-初始SessionFactory创建失败。org.hibernate.HibernateException:/hibernate.cfg.xml未找到 - Getting the following error - Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found 最初的SessionFactory创建失败。org.hibernate.HibernateException:缺少列:dept_id - Initial SessionFactory creation failed.org.hibernate.HibernateException: Missing column: dept_id 初始SessionFactory创建失败.org.hibernate.MappingException:配置无效 - Initial SessionFactory creation failed.org.hibernate.MappingException: invalid configuration 初始SessionFactory创建失败:org.hibernate.MappingException:无效的配置 - Initial SessionFactory creation failed: org.hibernate.MappingException: invalid configuration Hibernate初始SessionFactory创建失败 - Hibernate Initial SessionFactory creation failed 初始SessionFactory创建失败.org.hibernate.MappingException:重复列 - Initial SessionFactory creation failed.org.hibernate.MappingException: Repeated column 无法创建sessionFactory object.org.hibernate.HibernateException:无法初始化侦听器 - Failed to create sessionFactory object.org.hibernate.HibernateException: could not init listeners 在hibernate错误中初始SessionFactory创建失败 - Initial SessionFactory creation failed in hibernate error 初始SessionFactory创建失败.org.hibernate.AnnotationException:net.viralpatel.hibernate.Employee.department上的@OneToOne或@ManyToOne - Initial SessionFactory creation failed.org.hibernate.AnnotationException: @OneToOne or @ManyToOne on net.viralpatel.hibernate.Employee.department
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM