测试时出现了这样的错误,我知道是News.hbm.xml配置有问题,麻烦各位帮帮忙,看一下是那的问题?
package cn.ts.ssh.model;import java.util.Date;
import java.util.Set;public class News extends BaseObject {
/**
 * @author Administrator
 * @描述:Hibernate的类对应的表为:news;
 * 
 */
private long id;
private String title;
private String content;
private User poster;
private Date postDate;
private Date lastModifyDate;
private Category category;
private Set newsReviews;
/**
 * @function 消息Id
 * 
 */
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
/**
 * @function 消息标题
 * @return
 */
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
/**
 * @function 消息内容
 * @return
 */
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
/**
 * @function 消息发布者
 * @return
 */
public User getPoster() {
return poster;
}
public void setPoster(User poster) {
this.poster = poster;
}
/**
 * @function 消息发布日期
 * @return
 */
public Date getPostDate() {
return postDate;
}
public void setPostDate(Date postDate) {
this.postDate = postDate;
}
/**
 * @function 消息最后修改日期
 * @return
 */
public Date getLastModifyDate() {
return lastModifyDate;
}
public void setLastModifyDate(Date lastModifyDate) {
this.lastModifyDate = lastModifyDate;
}
/**
 *@function 消息分类
 * @return
 */ public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
/**
 * @function 消息评论
 * @return
 */
public Set getNewsReviews() {
return newsReviews;
}
public void setNewsReviews(Set newsReviews) {
this.newsReviews = newsReviews;
}

@Override
public String toString() {
// TODO Auto-generated method stub
return null;

}
@Override
public boolean equals(Object object) {
// TODO Auto-generated method stub
if (! (object instanceof News)){
return false;
}
News rhs = (News) object;
return this.poster.equals(rhs.getPoster())
&& this.postDate.equals(rhs.getPostDate());

}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return this.poster.hashCode()+this.postDate.hashCode();

}


}映射文件如下:
<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.ts.ssh.model">
    <class name="cn.ts.hibernate.model.News" table="news_table">
         <id name="id" column="id"  type="java.lang.Integer">
         <generator class="increment"></generator>
         </id>
        <many-to-one name="category" class="cn.ts.ssh.Category" column="category_id" not-null="true" ></many-to-one>
         <property name="lastmodifydate" column="Last_modify_date" not-null="true" type="java.util.Date"></property>
         <property name="postdate" column="post_date" not-null="true" type="java.util.Date" ></property>
         <many-to-one name="poster" class="cn.ts.ssh.User" column="username" not-null="true"></many-to-one>
          <property name="content" column="content"  length="3000" not-null="true"></property>
          <property name="title" column="title" length="50" not-null="true"></property>
          <set name="newsReview" lazy="false" inverse="true" table="newsreview_table">
          <key column="id" not-null="true">
          </key>
          <element type="string" column="newsreview" not-null="true"></element>
          </set>
            
    </class>   
</hibernate-mapping>测试时出现这样的提示:
org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/ts/ssh/model/News.hbm.xml
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3411)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3400)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3388)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1733)
at cn.ts.ssh.service.NewsAonnouncedService.addNews(NewsAonnouncedService.java:58)
at cn.ts.ssh.test.TestNewsAnnouncedService.testAddNews(TestNewsAnnouncedService.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
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 cn.ts.hibernate.model.News not found while looking for property: content
at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:232)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:326)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2267)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2232)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2122)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:406)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:321)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:172)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3408)
... 28 more
Caused by: java.lang.ClassNotFoundException: cn.ts.hibernate.model.News
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:228)
... 36 more我一直在找,一直没找到。在此先谢谢各位的劳神费心的给我解决这样的小问题。

解决方案 »

  1.   

    package="cn.ts.ssh.model"
    cn.ts.hibernate.model.News
    你不在一个包下啊
      

  2.   


    我改了可又有新问题了
    org.hibernate.MappingException: An association from the table news_table refers to an unmapped class: cn.ts.ssh.User
    at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1699)
    at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1633)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1733)
    at cn.ts.ssh.service.NewsAonnouncedService.addNews(NewsAonnouncedService.java:58)
    at cn.ts.ssh.test.TestNewsAnnouncedService.testAddNews(TestNewsAnnouncedService.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    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.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    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)
      

  3.   

    朋友这才是你真正的包名:cn.ts.ssh.model;
    把你的配置文件的这句话<class name="cn.ts.hibernate.model.News" table="news_table">
    改成:<class name="cn.ts.ssh.model.News" table="news_table">
      

  4.   

    User.java是有的在同一个包中:
    User单独测试是成功的
    那再怎么办
      

  5.   

    news_table 你没有配置映射文件啊