class CostDetail not found while looking for property: id

xiaohuili_10 2009-09-14 05:31:24
vo代码:
package com.cost.orm.vo;

/** @pdOid eaa2bf14-b9a6-4083-9c39-867276417c3e */
public class CostType implements java.io.Serializable {
private static final long serialVersionUID = -5975636415761830236L;
/** @pdOid 23dd5677-0440-4ded-93bb-519e6caa8111 */
public int id;
/** @pdOid 4e1c63ef-dd5d-4cd1-b58f-d0673021a309 */
public java.lang.String name;
/** @pdOid e3b20095-8634-42d0-a673-89a7ddc96361 */
public java.lang.String marke;

/** @pdRoleInfo migr=no name=CostDetail assc=reference1 mult=1..1 */
public CostDetail costDetail;

/**
* Empty constructor which is required by Hibernate
*
*/
public CostType() {
// TODO Auto-generated constructor stub
}

/**
* @pdGenerated default parent getter
*/
public CostDetail getCostDetail() {
return costDetail;
}

/**
* @pdGenerated default parent setter
* @param newCostDetail
*/
public void setCostDetail(CostDetail newCostDetail) {
if (this.costDetail == null || !this.costDetail.equals(newCostDetail)) {
CostDetail oldCostDetail = this.costDetail;
this.costDetail = newCostDetail;
if (oldCostDetail != null)
oldCostDetail.setCostType(null);
// Re-assign the value
this.costDetail = newCostDetail;
if (this.costDetail != null)
this.costDetail.setCostType(this);
}
}

/**
* Get value of id
*
* @return id
*/
public int getId() {
return id;
}

/**
* Set value of id
*
* @param newId
*/
public void setId(int newId) {
this.id = newId;
}

/**
* Get value of name
*
* @return name
*/
public java.lang.String getName() {
return name;
}

/**
* Set value of name
*
* @param newName
*/
public void setName(java.lang.String newName) {
this.name = newName;
}

/**
* Get value of marke
*
* @return marke
*/
public java.lang.String getMarke() {
return marke;
}

/**
* Set value of marke
*
* @param newMarke
*/
public void setMarke(java.lang.String newMarke) {
this.marke = newMarke;
}

/**
* Get value of costTypePK.
*
* @return costTypePK object
*/
public CostTypePK getCostTypePK() {
return new CostTypePK(id);
}

/**
* Set value of costTypePK.
*
* @param pk
*/
public void setCostTypePK(CostTypePK pk) {
if (pk != null) {
this.id = pk.getId();
}
}

/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object other) {

if (other == null)
return false;

if (other == this)
return true;

if (!(other instanceof CostType))
return false;

CostType cast = (CostType) other;

if (this.id != cast.getId())
return false;

if (this.name == null ? cast.getName() != this.name : !this.name
.equals(cast.getName()))
return false;

if (this.marke == null ? cast.getMarke() != this.marke : !this.marke
.equals(cast.getMarke()))
return false;

return true;
}

/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
int hashCode = 0;
hashCode = 29 * hashCode + (new Integer(id)).hashCode();
if (this.name != null)
hashCode = 29 * hashCode + name.hashCode();
if (this.marke != null)
hashCode = 29 * hashCode + marke.hashCode();
return hashCode;
}

/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer ret = new StringBuffer();
ret.append("CostType: ");
ret.append("id='" + id + "'");
ret.append("name='" + name + "'");
ret.append("marke='" + marke + "'");
return ret.toString();
}

}
映射文件代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.cost.orm.vo">
<class abstract="false" lazy="true" name="CostType"
table="COST_TYPE">
<id name="id">
<column name="ID" not-null="true" sql-type="int" />
</id>
<property generated="never" insert="true" lazy="false" name="name"
update="true">
<column length="50" name="NAME" sql-type="varchar(50)" />
</property>
<property generated="never" insert="true" lazy="false" name="marke"
update="true">
<column length="100" name="MARKE" sql-type="varchar(100)" />
</property>
<one-to-one class="CostDetail" name="costDetail"
outer-join="false" property-ref="costType" />
</class>
</hibernate-mapping>
以上都是由pwoerdesigner15自动生成,测试代码:
@Test
public void insertTest(){
Session session = null;
Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
Transaction trans = null;
trans = session.beginTransaction();
CostType type = new CostType();
type.setName("Micheal");
session.save(type);
session.flush();
trans.commit();
Assert.assertEquals(type.getId() > 0, true);
session.close();
}
JUNIT报错信息:
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/cost/orm/vo/CostDetail.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at test.ConnectionTest.insertTest(ConnectionTest.java:25)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.MappingException: class CostDetail not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:232)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:423)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:356)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:716)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 30 more
Caused by: java.lang.ClassNotFoundException: CostDetail
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:228)
... 38 more
求高手解惑!
...全文
1243 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
大佬孙 2010-08-11
  • 打赏
  • 举报
回复
没高手吗?我也是这个错!

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧