很抱歉打扰你。我是hibernate的新手,我有映射问题。我认为这将是一个愚蠢的错误,但我无法独自处理这个问题。我不会描述整个数据库(它太大了),......只是有错误的一部分。我有2张桌子。第一个名为“Accounts”的人:
CREATE TABLE `accounts` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`nick` varchar(15) DEFAULT NULL,
`password` varchar(15) DEFAULT NULL,
`firstname` varchar(15) DEFAULT NULL,
`secondname` varchar(15) DEFAULT NULL,
`sex` binary(1) DEFAULT NULL,
`birth` date DEFAULT NULL,
`about` varchar(100) DEFAULT NULL,
`photo` varchar(45) DEFAULT NULL,
`profesion` varchar(45) DEFAULT NULL,
`interests` varchar(70) DEFAULT NULL,
`address` varchar(45) DEFAULT NULL,
`login_timestamp` datetime DEFAULT NULL,
`temporal_hash` varchar(45) DEFAULT NULL,
`phone` varchar(20) DEFAULT NULL,
`permission_id` int(2) unsigned DEFAULT NULL,
`mail` varchar(45) DEFAULT NULL,
`language_id` int(11) unsigned DEFAULT NULL,
`backup_mail` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=big5;
此表与表“connection”具有一对多的关系
CREATE TABLE `connection` (
`id` int(11) unsigned NOT NULL,
`host` varchar(20) DEFAULT NULL,
`date` datetime DEFAULT NULL,
`description` varchar(45) DEFAULT NULL,
`user_id` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf32;
列“user_id”标识用户帐户。
以下是Accounts实体的映射XML文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.service.hibernate.entities.Accounts" table="accounts">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native" />
</id>
<property name="nick" type="java.lang.String" column="nick"/>
<property name="password" type="java.lang.String" column="password"/>
<property name="firstname" type="java.lang.String" column="firstname" />
<property name="secondname" type="java.lang.String" column="secondname"/>
<property name="sex" type="java.lang.Boolean" column="sex"/>
<property name="birth" type="java.util.Date" column="birth"/>
<property name="about" type="java.lang.String" column="about"/>
<property name="photo" type="java.lang.String" column="photo"/>
<property name="profesion" type="java.lang.String" column="profesion"/>
<property name="interests" type="java.lang.String" column="interests"/>
<property name="address" type="java.lang.String" column="address"/>
<property name="login_timestamp" type="java.util.Date" column="login_timestamp"/>
<property name="temporal_hash" type="java.lang.String" column="temporal_hash"/>
<property name="phone" type="java.lang.String" column="phone"/>
<property name="mail" type="java.lang.String" column="mail"/>
<property name="backup_mail" type="java.lang.String" column="backup_mail"/>
.
.
.
<!-- CONNECTION LOG - KURVA NECHAPEM. NIE A NIE NAPAMPOVAT TU POSRANU ENTITU. O CO JE INAKSIA AKO NAPR FORUM ??? -->
<set name="connections" table="connection" inverse="true" lazy="true" fetch="select">
<key column="user_id" />
<one-to-many class="com.service.hibernate.entities.Connetion" />
</set>
.
.
.
</class>
</hibernate-mapping>
以下是“连接”实体的映射XML文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.service.hibernate.entities.Connection" table="connection">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native" />
</id>
<property name="host" type="java.lang.String" column="host"/>
<property name="date" type="java.util.Date" column="date"/>
<property name="description" type="java.lang.String" column="description"/>
<property name="user_id" type="java.lang.Integer" column="user_id"/>
</class>
</hibernate-mapping>
hibernate.cfg.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">qayxsw</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.default_schema">training</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
.
.
.
<mapping resource="com/service/hibernate/map_xml/Accounts.hbm.xml"/>
<mapping resource="com/service/hibernate/map_xml/Connection.hbm.xml"/>
.
.
.
</session-factory>
</hibernate-configuration>
以下是错误消息:
Initial SessionFactory creation failed.org.hibernate.MappingException: Association references unmapped class: com.service.hibernate.entities.Connetion
null
Mar 31, 2015 6:45:26 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.ExceptionInInitializerError
at com.service.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:20)
at com.service.utils.HibernateUtil.<clinit>(HibernateUtil.java:9)
at com.service.user.UserServices.userAuthentication(UserServices.java:221)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.MappingException: Association references unmapped class: com.service.hibernate.entities.Connetion
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2577)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2828)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at com.service.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:15)
... 44 more
Mar 31, 2015 6:45:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey] in context with path [/RESTfulWebService] threw exception [java.lang.ExceptionInInitializerError] with root cause
org.hibernate.MappingException: Association references unmapped class: com.service.hibernate.entities.Connetion
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2577)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2828)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at com.service.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:15)
at com.service.utils.HibernateUtil.<clinit>(HibernateUtil.java:9)
at com.service.user.UserServices.userAuthentication(UserServices.java:221)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
错误说:关联引用未映射的类:com.service.hibernate.entities.Connetion
但我不认为有错误:(。有趣的是,我在数据库中有更多的6对一对多关系,但只有这一个不起作用。我找不到区别他们之间:D
班级联系:
package com.service.hibernate.entities;
import java.util.Date;
public class Connection implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 8191028135531498491L;
private Integer id = null;
private String host = null;
private Date date = null;
private String description = null;
private Integer user_id = null;
public Connection(){
this(null,null,null,null,null);
}
public Connection(Integer id, String host, Date date, String description, Integer user_id) {
super();
this.id = id;
this.host = host;
this.date = date;
this.description = description;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getUser_id() {
return user_id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
}
感谢您的帮助:)。最诚挚的问候