欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题 HibernateJavaAntApacheIDEA

程序员文章站 2022-03-14 21:46:52
...
软件版本:
hibernate-3.2.0.cr2
hibernate-annotations-3.2.0.CR1

IDE:
idea 5.1

以前都是用XDoclet来实现类似Annotation的功能,但是xdoclet的版本更新实在太慢,永远跟不上hibernate的更新速度,导致很多hibernate新的功能xdoclet都没办法支持.还好,jdk5.0有了Annotation,而且hibernate也开始支持Annotation了.

原来以为从xdoclet转到Annotation很简单,没想到还是遇到了问题,先看代码:

 1解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEApackage test;
 2解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
 3解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport org.hibernate.annotations.Entity;
 4解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
 5解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport javax.persistence.Id;
 6解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport java.io.Serializable;
 7解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
 8解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA@Entity
 9解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEApublic class Flight implements Serializable解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA{
10解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  Long id;
11解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  String name;
12解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
13解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  @Id
14解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  public Long getId()解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA{
15解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    return id;
16解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  }

17解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
18解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  public void setId(Long id)解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA{
19解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    this.id=id;
20解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  }

21解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
22解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  public String getName()解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA{
23解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    return name;
24解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  }

25解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
26解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  public void setName(String name)解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA{
27解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    this.name=name;
28解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  }

29解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
30解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  public boolean equals(Object o)解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA{
31解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    if(this==o) return true;
32解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    if(o==null||getClass()!=o.getClass()) return false;
33解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
34解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    final Flight flight=(Flight)o;
35解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
36解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    if(id!=null?!id.equals(flight.id):flight.id!=nullreturn false;
37解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    if(name!=null?!name.equals(flight.name):flight.name!=nullreturn false;
38解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
39解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    return true;
40解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  }

41解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
42解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  public int hashCode()解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA{
43解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    int result;
44解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    result=(id!=null?id.hashCode():0);
45解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    result=29*result+(name!=null?name.hashCode():0);
46解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA    return result;
47解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA  }

48解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA}

49解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA


看上去没什么问题吧?没想到运行的时候根本跑不起来,老是提示:
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java] 10:54:55,842  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java] org.hibernate.hql.ast.QuerySyntaxException: Flight is not mapped [from Flight]
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:
180)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:
710)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:
178)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:
84)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:
275)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Task.perform(Task.java:
364)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Target.execute(Target.java:
341)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:
369)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:
1216)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:
1185)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:
40)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:
1068)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:
668)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.Main.startAnt(Main.java:
187)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:
246)
解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA     [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:
67)

看了半天看不出有什么问题,最后终于参考hibernate-annotations-3.2.0.CR1里面单元测试的代码才发现是这段代码有问题:

1解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport org.hibernate.annotations.Entity;
2解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA
3解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport javax.persistence.Id;
4解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport java.io.Serializable;
5解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA


要改成:

1解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport javax.persistence.Id;
2解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport javax.persistence.Entity;
3解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEAimport java.io.Serializable;


原来我用idea开发时,在自动完成的时候想当然地选用了org.hibernate.annotations包下面的annotation,而实际上应该使用javax.persistence包下面的annotation.想想看也很有道理:这样一来我们的JAVA bean就不用import hibernate的包了,用的都是标准的java包.解决 Hibernate Annotation 的 "no persistent classes found for query class" 问题
            
    
    
        HibernateJavaAntApacheIDEA

一餐三碗 2006-06-30 11:04 发表评论