MappingException的Unknown entity class错误
做的是一个联合主键的例子,不知道和这个有关没有。
net.sf.hibernate.MappingException: Unknown entity class: wyj.pojo.Tuser2
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:347)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2710)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2717)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:772)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
at wyj.CompositeKey.insert(CompositeKey.java:57)
at wyj.CompositeKey.main(CompositeKey.java:93)
POJO和hbm.xml是用MiddleGen和Extension生成的。wyj.pojo.Tuser2是映射的类
问题点数:100、回复次数:6Top
1 楼boy1(Spike)回复于 2006-01-10 14:44:35 得分 0
public void insert(String firstName, String lastName) {
Transaction tran = null;
List emailList = new ArrayList();
try {
Tuser2PK userPK = new Tuser2PK(firstName, lastName);
Tuser2 user = new Tuser2();
user.setComp_id(userPK);
user.setAge(new Integer(25));
session.save(user); //异常
session.flush();
} catch (HibernateException ex) {
ex.printStackTrace();
if(tran != null) {
try {
tran.rollback();
} catch(HibernateException e) {
e.printStackTrace();
}
}
}
}Top
2 楼bluelily22(丁丁)回复于 2006-01-10 15:37:08 得分 50
hibernate.cfg.xml
有没有把你的类写到mapping 中呀
<mapping resource="wyj/pojp/Tuser2.hbm.xml" />
Top
3 楼zeq258(周二强)回复于 2006-01-10 18:11:14 得分 50
检查楼上说的这个问题,
如果还不行,把代码铁出来,包括 hibernate.cfg.xml ,和 .hbm.xmlTop
4 楼boy1(Spike)回复于 2006-01-11 12:30:58 得分 0
Tuser2.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="wyj.pojo.Tuser2"
table="t_user_2"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="t_user_2"
</meta>
<composite-id name="comp_id" class="wyj.pojo.Tuser2PK">
<meta attribute="field-description" inherit="false">
@hibernate.id
generator-class="assigned"
</meta>
<key-property
name="firstname"
column="firstname"
type="java.lang.String"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="firstname"
</meta>
</key-property>
<key-property
name="lastname"
column="lastname"
type="java.lang.String"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="lastname"
</meta>
</key-property>
</composite-id>
<property
name="age"
type="java.lang.Integer"
column="age"
length="11"
>
<meta attribute="field-description">
@hibernate.property
column="age"
length="11"
</meta>
</property>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
</class>
</hibernate-mapping>
Top
5 楼boy1(Spike)回复于 2006-01-11 12:32:07 得分 0
package wyj.pojo;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class Tuser2PK implements Serializable {
/** identifier field */
private String firstname;
/** identifier field */
private String lastname;
/** full constructor */
public Tuser2PK(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
/** default constructor */
public Tuser2PK() {
}
/**
* @hibernate.property
* column="firstname"
*
*/
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
/**
* @hibernate.property
* column="lastname"
*
*/
public String getLastname() {
return this.lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String toString() {
return new ToStringBuilder(this)
.append("firstname", getFirstname())
.append("lastname", getLastname())
.toString();
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof Tuser2PK) ) return false;
Tuser2PK castOther = (Tuser2PK) other;
return new EqualsBuilder()
.append(this.getFirstname(), castOther.getFirstname())
.append(this.getLastname(), castOther.getLastname())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getFirstname())
.append(getLastname())
.toHashCode();
}
}
Top
6 楼boy1(Spike)回复于 2006-01-11 12:32:52 得分 0
package wyj.pojo;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @hibernate.class
* table="t_user_2"
*
*/
public class Tuser2 implements Serializable {
/** identifier field */
private wyj.pojo.Tuser2PK comp_id;
/** nullable persistent field */
private Integer age;
/** full constructor */
public Tuser2(wyj.pojo.Tuser2PK comp_id, Integer age) {
this.comp_id = comp_id;
this.age = age;
}
/** default constructor */
public Tuser2() {
}
/** minimal constructor */
public Tuser2(wyj.pojo.Tuser2PK comp_id) {
this.comp_id = comp_id;
}
/**
* @hibernate.id
* generator-class="assigned"
*
*/
public wyj.pojo.Tuser2PK getComp_id() {
return this.comp_id;
}
public void setComp_id(wyj.pojo.Tuser2PK comp_id) {
this.comp_id = comp_id;
}
/**
* @hibernate.property
* column="age"
* length="11"
*
*/
public Integer getAge() {
return this.age;
}
public void setAge(Integer age) {
this.age = age;
}
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof Tuser2) ) return false;
Tuser2 castOther = (Tuser2) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
Top
相关问题
- 用过nhibernate大佬们帮忙看一下,Unknown entity class什么错误啊~
- 使用hibernate对对象进行持久化时,Unknown entity class的错误
- S+S+H填加用户时出现错误提示:nested exception is org.hibernate.MappingException: Unknown entity: com.sshdemo2.struts.form.LoginF
- 请教在JB中建立EJB时2个问题,CMP2.0 ENTITY Bean 与BMP Entity Bean有什么区别么?有个local home interface class是什么东西??谢谢
- class class
- JDO V.S. Entity Bean
- Base Class And Derived Class
- public class a和class a
- unknown character '0xa1'
- unknown object java.net.URL




