1

出于某种原因,Hibernate 在我的课程中没有看到 Getter,或者至少我认为这是正在发生的事情。我在休眠映射文件或不同的 XML 配置文件中是否设置了错误?

我向您展示的代码是由 WaveMaker 生成的,应该可以工作。我正在尝试运行一个简单的 HQL 查询,但我总是收到以下错误。不管查询有多简单或查询的是什么实体,我总是会收到“找不到吸气剂”错误。

我将 WaveMaker 6.5 与它在安装期间下载的任何版本的 Hibernate 和 Spring 一起使用。

这是我得到的错误:

Run query error: Error creating bean with name 'm2mex2DBDataService' defined in 
resource loaded through SAX InputSource: Cannot resolve reference to bean 
'm2mex2DBHibernateTemplate' while setting constructor argument; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'm2mex2DBHibernateTemplate' defined in resource loaded through SAX InputSource: Cannot 
resolve reference to bean 'm2mex2DBSessionFactory' while setting bean property 
'sessionFactory'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'm2mex2DBSessionFactory' defined in resource loaded through SAX InputSource: Invocation 
of init method failed; nested exception is org.hibernate.PropertyNotFoundException: 
Could not find a getter for bookauthors in class com.m2mex2db.data.Author

这是我的 Author 类的代码:

package com.m2mex2db.data;

import java.util.HashSet;
import java.util.Set;


/**
 *  m2mex2DB.Author
 *  05/08/2013 16:33:50
 * 
 */
public class Author {

private Integer id;
private String firstname;
private String lastname;
private Set<com.m2mex2db.data.Bookauthor> bookauthors = new HashSet<com.m2mex2db.data.Bookauthor>();

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getFirstname() {
    return firstname;
}

public void setFirstname(String firstname) {
    this.firstname = firstname;
}

public String getLastname() {
    return lastname;
}

public void setLastname(String lastname) {
    this.lastname = lastname;
}

public Set<com.m2mex2db.data.Bookauthor> getBookauthors() {
    return bookauthors;
}

public void setBookauthors(Set<com.m2mex2db.data.Bookauthor> bookauthors) {
    this.bookauthors = bookauthors;
}

}

这是我的休眠映射文件:

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.m2mex2db.data.Author" table="author" schema="kentoj" dynamic-insert="false" dynamic-update="false">
    <id name="id" type="integer">
        <column name="id"/>
        <generator class="assigned"/>
    </id>
    <property name="firstname" type="string">
        <column name="firstname" length="98" not-null="true"/>
    </property>
    <property name="lastname" type="string">
        <column name="lastname" length="98"/>
    </property>
    <set name="bookauthors" inverse="true" cascade="">
        <key>
            <column name="authorid" not-null="true"/>
        </key>
        <one-to-many class="com.m2mex2db.data.Bookauthor"/>
    </set>
</class>
</hibernate-mapping>
4