hibernate配置 h高手进 急!
数据库使用的是ms sqlserver2000+sp4 hibernate使用的是hibernate3.0 数据库设计中student表通过teamid外键关联team表,其它都是一些各自独立的字段,所有的映射文件都是通过hibernate插件自动生成的,我仔细查看了很久都不知问题出在哪里.
检查hibernate配置抛出异常如下:
org.hibernate.InvalidMappingException: Could not parse mapping document from file D:\Lomboz_eclipse\workspace1\TestHibernate\WEB-INF\src\th\vo\Student.hbm.xml
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping th.vo.Student
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping th.vo.Student
除此之外没有任何其它提示了!
程序中使用hql(from student)查询时抛出如下异常:
java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at th.test.Test.main(Test.java:31)
相关student vo 类如下:
package th.vo.base;
import java.io.Serializable;
public abstract class BaseStudent implements Serializable {
public static String REF = "Student";
public static String PROP_TEAMID = "Teamid";
public static String PROP_STUNAME = "Stuname";
public static String PROP_STUSEX = "Stusex";
public static String PROP_STUAGE = "Stuage";
public static String PROP_ID = "Id";
// constructors
public BaseStudent () {
initialize();
}
/**
* Constructor for primary key
*/
public BaseStudent (java.lang.String id) {
this.setId(id);
initialize();
}
protected void initialize () {}
private int hashCode = Integer.MIN_VALUE;
// primary key
private java.lang.String id;
// fields
private java.lang.String stuname;
private java.lang.String stusex;
private java.lang.Integer stuage;
// many to one
private th.vo.Team teamid;
/**
* Return the unique identifier of this class
* @hibernate.id
* generator-class="assigned"
* column="stuid"
*/
public java.lang.String getId () {
return id;
}
/**
* Set the unique identifier of this class
* @param id the new ID
*/
public void setId (java.lang.String id) {
this.id = id;
this.hashCode = Integer.MIN_VALUE;
}
/**
* Return the value associated with the column: stuname
*/
public java.lang.String getStuname () {
return stuname;
}
/**
* Set the value related to the column: stuname
* @param stuname the stuname value
*/
public void setStuname (java.lang.String stuname) {
this.stuname = stuname;
}
/**
* Return the value associated with the column: stusex
*/
public java.lang.String getStusex () {
return stusex;
}
/**
* Set the value related to the column: stusex
* @param stusex the stusex value
*/
public void setStusex (java.lang.String stusex) {
this.stusex = stusex;
}
/**
* Return the value associated with the column: stuage
*/
public java.lang.Integer getStuage () {
return stuage;
}
/**
* Set the value related to the column: stuage
* @param stuage the stuage value
*/
public void setStuage (java.lang.Integer stuage) {
this.stuage = stuage;
}
/**
* Return the value associated with the column: teamid
*/
public th.vo.Team getTeamid () {
return teamid;
}
/**
* Set the value related to the column: teamid
* @param teamid the teamid value
*/
public void setTeamid (th.vo.Team teamid) {
this.teamid = teamid;
}
public boolean equals (Object obj) {
if (null == obj) return false;
if (!(obj instanceof th.vo.Student)) return false;
else {
th.vo.Student student = (th.vo.Student) obj;
if (null == this.getId() || null == student.getId()) return false;
else return (this.getId().equals(student.getId()));
}
}
public int hashCode () {
if (Integer.MIN_VALUE == this.hashCode) {
if (null == this.getId()) return super.hashCode();
else {
String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
this.hashCode = hashStr.hashCode();
}
}
return this.hashCode;
}
public String toString () {
return super.toString();
}
}
package th.vo;
import th.vo.base.BaseStudent;
public class Student extends BaseStudent {
private static final long serialVersionUID = 1L;
/*[CONSTRUCTOR MARKER BEGIN]*/
public Student () {
super();
}
/**
* Constructor for primary key
*/
public Student (java.lang.String id) {
super(id);
}
/*[CONSTRUCTOR MARKER END]*/
}
student 映射文件如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="th.vo">
<class
name="Student"
table="student"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="string"
column="stuid"
>
<generator class="assigned"/>
</id>
<property
name="Stuname"
column="stuname"
type="string"
not-null="false"
length="20"
/>
<property
name="Stusex"
column="stusex"
type="string"
not-null="false"
length="4"
/>
<property
name="Stuage"
column="stuage"
type="integer"
not-null="false"
length="10"
/>
<many-to-one
name="Teamid"
column="teamid"
class="Team"
not-null="false"
>
</many-to-one>
</class>
</hibernate-mapping>