- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
JBoss AS 7.0.1.Final,Hibernate 3。我们有一个 MySQL 数据源。
我有指向 *hbm.xml 文件的映射资源。我收到部署错误,告诉我“资源:* hbm.xml 未找到”,因此实体未正确映射 - 此堆栈跟踪是由于未找到 User.hbm.xml,
14:44:34,654 INFO [org.hibernate.cfg.Configuration] (MSC service thread 1-9) HHH00042:Configuring from file: hibernate.cfg.xml
14:44:34,668 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] (MSC service thread 1-9) HHH00223:Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
14:44:34,670 INFO [org.hibernate.cfg.Configuration] (MSC service thread 1-9) HHH00221:Reading mappings from resource: User.hbm.xml
14:44:34,697 SEVERE [com.mycompany.myapp.common.persistence.HibernateUtil] (MSC service thread 1-9) Initial SessionFactory lookup failed.: org.hibernate.MappingNotFoundException: resource: User.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:720) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2083) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2055) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2035) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1988) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
at org.hibernate.cfg.Configuration.configure(Configuration.java:1961) [hibernate-core-4.0.0.Beta5.jar:4.0.0.Beta5]
at com.mycompany.myapp.common.persistence.HibernateUtil.<clinit>(HibernateUtil.java:42) [classes:]
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:216) [classes:]
at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
14:44:34,698 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter EnterpriseSecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
14:44:34,699 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter CompanySecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
14:44:34,701 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter StationSecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
at com.mycompany.myapp.common.servlet.SecurityFilter.init(SecurityFilter.java:55) [classes:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
14:44:34,702 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp-maventest]] (MSC service thread 1-9) Exception starting filter StudioSecurityFilter: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:224) [classes:]
at com.mycompany.myapp.studio.StudioSecurityFilter.init(StudioSecurityFilter.java:46) [classes:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]
我们的项目结构如下
Project
|
|-pom.xml
|
|-src
| |-main
| |-java
| | |-com... businessobjects
| |-resources
| | |-META-INF
| |-webapp
|
|-test
我们在 src/main/resources/META-INF 中有 hibernate.cfg.xml,在 src/main/java/com/businessobjects/中有各种 *.class 和 *hbm.xml。我们的 hibernate.cfg.xml 看起来像
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="datasourceName">java:jboss/datasources/MySqlDS</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/mycompany/myapp/common/businessobjects/User.hbm.xml"/>
<mapping resource="com/mycompany/myapp/common/businessobjects/Company.hbm.xml"/>
<mapping resource="com/mycompany/myapp/common/businessobjects/ServerSettings.hbm.xml"/>
<mapping resource="com/mycompany/myapp/common/businessobjects/Station.hbm.xml"/>
</session-factory>
</hibernate-configuration>
我尝试了不同的路径来指向 *hbm.xml 文件 - 似乎都不起作用。我什至尝试过为它提供 *hbm.xml 文件的绝对路径,但这也不起作用。
我也试过将 *hbm.xml 复制到与 hibernate.cfg.xml 相同的目录中 - 这也没有用,同样的错误。
看起来我的 HibernateUtil 类的代码此时出错了
static {
try {
InitialContext ctx = new InitialContext();
Configuration configuration = new Configuration();
Properties properties = new Properties();
sessionFactory = configuration.configure(
new File("/path/to/src/main/resources/META-INF/hibernate.cfg.xml")
).buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
log.error("Initial SessionFactory lookup failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}
有什么想法吗?谢谢
最佳答案
将您的映射文件移至 src/main/resources。只有 .java 文件属于 src/main/java。
编辑:我设置了一个 example project on github显示如何从 hibernate.cfg.xml 正确引用 XML 映射文件。
关于java - org.hibernate.MappingNotFoundException : resource: *hbm. 找不到 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7127608/
我使用 Netbeans IDE。 我的 hibernate.cfg.xml 看起来像这样: //properties hibernate.cfg.xm
在 SpringMVC 的 src/main/resources 中,我有我的 hibernate.cfg.xml 我在 src/main/java org.david.model.UserDetai
我已关注this教程。 这是我的文件夹结构: 当我运行 App.Java 时,我得到: Initial SessionFactory creation failed.org.hibernate.Map
我是 Hibernate 的新手。我正在尝试运行一个简单的查询来查看给定的用户登录信息是否正确: public boolean checkLogin(String user, String pw) {
我的问题是: 现在我的 SPRING-CFG.xml 看起来像这样spring-cfg.xml
我正在尝试做一个简单的 hibernate 程序。我正在按照此 tutorial 中给出的步骤进行操作. 我得到的错误是 org.hibernate.MappingNotFoundExcepti
我正在尝试在 IntelliJ 的 Hibernate 控制台中运行 HQL 查询。我已将数据源添加到“数据源” View ,并将 hibernate.cfg.xml 添加到 Hibernate 方面
我有一个 Eclipse 动态 Web 项目,它托管一个简单的 servlet 并在 Tomcat 上运行。我在内部使用 Hibernate - 我在我的项目中有映射到数据库表和 hbm.xml 文件
JBoss AS 7.0.1.Final,Hibernate 3。我们有一个 MySQL 数据源。 我有指向 *hbm.xml 文件的映射资源。我收到部署错误,告诉我“资源:* hbm.xml 未找到
我一直在尝试用一个小例子来实现 hibernate 。 下面是我的hibernate.config.xml com.mysql.jdbc.Driver jdbc:mysql://loca
我尝试在 MYSQL 中连接,但在尝试添加配置下一个资源:hibernate.cfg.xml 时出现错误。并有下一个错误 org.hibernate.MappingNotFoundException:
我正在java中做hibernate示例。下面是使用的代码 Hibernate.cfg.xml com.mysql.jdbc.Driver root jdbc:mysql://local
我在测试该方法时遇到问题: org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines 信息: D
不,这与 this one 不是同一个问题或this one或this one . 原因很简单,我的 *.hbm.xml 文件已经位于正确的目录中 (src/main/resources/com/co
我是一名优秀的程序员,十分优秀!