当前位置: 首页 > 知识库问答 >
问题:

需要帮助获得Spring,Hibernate项目再次使用Hibernate逆向工程创建类

赫连靖琪
2023-03-14
    log.debug("Looking for data for:" + requester);


    MemberInquiryLookup dr = (MemberInquiryLookup)
            sessionFactory.getCurrentSession()
            .get(MemberInquiryLookup.class, requester);
    if (dr == null) {
        log.debug("NO DATA for :" + requester + " was found.");

        dr = new MemberInquiryLookup();
    }
    return dr;

}
@Entity
@Table(name = " member_inquiry_lookup")
public class MemberInquiryInformation {

    @Id
    @Column(name = "email")
    private String email;

    @Column(name = "first_name")
    private String First_Name;

    @Column(name = "last_name")
    private String Last_Name;

    public String getFirst_Name() {
        return First_Name;
    }

    public void setFirst_Name(String first_Name) {
        First_Name = first_Name;
    }

    public String getLast_Name() {
        return Last_Name;
    }

    public void setLast_Name(String last_Name) {
        Last_Name = last_Name;
    }

    @Column(name = "member_id")
    private String member_id;

    @Column(name = "school_id")
    private String school_id;

    @Column(name = "title_id")
    private String title_id;

    @Column(name = "title_description")
    private String title_description;

    @Column(name = "school_search_name")
    private String school_search_name;

    @Column(name = "borough_description")
    private String borough_description;

    @Column(name = "district")
    private String district;

    @Column(name = "phone")
    private String phone;

    @Column(name = "file_number")
    private String file_number;

    @Column(name = "member_group")
    private String member_group;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMember_id() {
        return member_id;
    }

    public void setMember_id(String member_id) {
        this.member_id = member_id;
    }

    public String getSchool_id() {
        return school_id;
    }

    public void setSchool_id(String school_id) {
        this.school_id = school_id;
    }

    public String getTitle_id() {
        return title_id;
    }

    public void setTitle_id(String title_id) {
        this.title_id = title_id;
    }

    public String getTitle_description() {
        return title_description;
    }

    public void setTitle_description(String title_description) {
        this.title_description = title_description;
    }

    public String getSchool_search_name() {
        return school_search_name;
    }

    public void setSchool_search_name(String school_search_name) {
        this.school_search_name = school_search_name;
    }

    public String getBorough_description() {
        return borough_description;
    }

    public void setBorough_description(String borough_description) {
        this.borough_description = borough_description;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getFile_number() {
        return file_number;
    }

    public void setFile_number(String file_number) {
        this.file_number = file_number;
    }

    public String getMember_group() {
        return member_group;
    }

    /**
     * @return
     */
    public String getQueue() {
        if (getMember_group().equalsIgnoreCase("RT"))
            return "Retiree";

        return getBorough_description();

        /*if (getBorough_description().equalsIgnoreCase("BRONX"))
            return Constants.BRONX;

        if (getBorough_description().equalsIgnoreCase("BROOKLYN"))
            return Constants.BROOKLYN;

        if (getBorough_description().equalsIgnoreCase("QUEENS"))
            return Constants.QUEENS;

        if (getBorough_description().equalsIgnoreCase("MANHATTAN"))
            return Constants.MANATTAN;

        if (getBorough_description().equalsIgnoreCase("STATEN ISLAND"))
            return Constants.STATENISLAND;*/

    }

    public void setMember_group(String member_group) {
        this.member_group = member_group;
    }

}
@Entity
@Table(name = "member_inquiry_lookup")
public class MemberInquiryLookup implements java.io.Serializable {

    private MemberInquiryLookupId id;

    public MemberInquiryLookup() {
    }

    public MemberInquiryLookup(MemberInquiryLookupId id) {
        this.id = id;
    }

    @EmbeddedId
    @AttributeOverrides({
            @AttributeOverride(name = "email", column = @Column(name = "email", nullable = false)),
            @AttributeOverride(name = "memberId", column = @Column(name = "member_id")),
            @AttributeOverride(name = "firstName", column = @Column(name = "first_name", length = 15)),
            @AttributeOverride(name = "lastName", column = @Column(name = "last_name", length = 25)),
            @AttributeOverride(name = "schoolId", column = @Column(name = "school_id", length = 10)),
            @AttributeOverride(name = "titleId", column = @Column(name = "title_id", length = 5)),
            @AttributeOverride(name = "titleDescription", column = @Column(name = "title_description", length = 60)),
            @AttributeOverride(name = "schoolSearchName", column = @Column(name = "school_search_name")),
            @AttributeOverride(name = "boroughDescription", column = @Column(name = "borough_description")),
            @AttributeOverride(name = "district", column = @Column(name = "district")),
            @AttributeOverride(name = "phone", column = @Column(name = "phone", length = 16)),
            @AttributeOverride(name = "fileNumber", column = @Column(name = "file_number", length = 9)),
            @AttributeOverride(name = "memberGroup", column = @Column(name = "member_group", length = 4)) })
    public MemberInquiryLookupId getId() {
        return this.id;
    }

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

}

@Embeddable
public class MemberInquiryLookupId implements java.io.Serializable {

    private String email;
    private Integer memberId;
    private String firstName;
    private String lastName;
    private String schoolId;
    private String titleId;
    private String titleDescription;
    private String schoolSearchName;
    private String boroughDescription;
    private String district;
    private String phone;
    private String fileNumber;
    private String memberGroup;

    public MemberInquiryLookupId() {
    }

    public MemberInquiryLookupId(String email) {
        this.email = email;
    }

    public MemberInquiryLookupId(String email, Integer memberId,
            String firstName, String lastName, String schoolId, String titleId,
            String titleDescription, String schoolSearchName,
            String boroughDescription, String district, String phone,
            String fileNumber, String memberGroup) {
        this.email = email;
        this.memberId = memberId;
        this.firstName = firstName;
        this.lastName = lastName;
        this.schoolId = schoolId;
        this.titleId = titleId;
        this.titleDescription = titleDescription;
        this.schoolSearchName = schoolSearchName;
        this.boroughDescription = boroughDescription;
        this.district = district;
        this.phone = phone;
        this.fileNumber = fileNumber;
        this.memberGroup = memberGroup;
    }

    @Column(name = "email", nullable = false)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "member_id")
    public Integer getMemberId() {
        return this.memberId;
    }

    public void setMemberId(Integer memberId) {
        this.memberId = memberId;
    }

    @Column(name = "first_name", length = 15)
    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name = "last_name", length = 25)
    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name = "school_id", length = 10)
    public String getSchoolId() {
        return this.schoolId;
    }

    public void setSchoolId(String schoolId) {
        this.schoolId = schoolId;
    }

    @Column(name = "title_id", length = 5)
    public String getTitleId() {
        return this.titleId;
    }

    public void setTitleId(String titleId) {
        this.titleId = titleId;
    }

    @Column(name = "title_description", length = 60)
    public String getTitleDescription() {
        return this.titleDescription;
    }

    public void setTitleDescription(String titleDescription) {
        this.titleDescription = titleDescription;
    }

    @Column(name = "school_search_name")
    public String getSchoolSearchName() {
        return this.schoolSearchName;
    }

    public void setSchoolSearchName(String schoolSearchName) {
        this.schoolSearchName = schoolSearchName;
    }

    @Column(name = "borough_description")
    public String getBoroughDescription() {
        return this.boroughDescription;
    }

    public void setBoroughDescription(String boroughDescription) {
        this.boroughDescription = boroughDescription;
    }

    @Column(name = "district")
    public String getDistrict() {
        return this.district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    @Column(name = "phone", length = 16)
    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Column(name = "file_number", length = 9)
    public String getFileNumber() {
        return this.fileNumber;
    }

    public void setFileNumber(String fileNumber) {
        this.fileNumber = fileNumber;
    }

    @Column(name = "member_group", length = 4)
    public String getMemberGroup() {
        return this.memberGroup;
    }

    public void setMemberGroup(String memberGroup) {
        this.memberGroup = memberGroup;
    }

    public boolean equals(Object other) {
        if ((this == other))
            return true;
        if ((other == null))
            return false;
        if (!(other instanceof MemberInquiryLookupId))
            return false;
        MemberInquiryLookupId castOther = (MemberInquiryLookupId) other;

        return ((this.getEmail() == castOther.getEmail()) || (this.getEmail() != null
                && castOther.getEmail() != null && this.getEmail().equals(
                castOther.getEmail())))
                && ((this.getMemberId() == castOther.getMemberId()) || (this
                        .getMemberId() != null
                        && castOther.getMemberId() != null && this
                        .getMemberId().equals(castOther.getMemberId())))
                && ((this.getFirstName() == castOther.getFirstName()) || (this
                        .getFirstName() != null
                        && castOther.getFirstName() != null && this
                        .getFirstName().equals(castOther.getFirstName())))
                && ((this.getLastName() == castOther.getLastName()) || (this
                        .getLastName() != null
                        && castOther.getLastName() != null && this
                        .getLastName().equals(castOther.getLastName())))
                && ((this.getSchoolId() == castOther.getSchoolId()) || (this
                        .getSchoolId() != null
                        && castOther.getSchoolId() != null && this
                        .getSchoolId().equals(castOther.getSchoolId())))
                && ((this.getTitleId() == castOther.getTitleId()) || (this
                        .getTitleId() != null && castOther.getTitleId() != null && this
                        .getTitleId().equals(castOther.getTitleId())))
                && ((this.getTitleDescription() == castOther
                        .getTitleDescription()) || (this.getTitleDescription() != null
                        && castOther.getTitleDescription() != null && this
                        .getTitleDescription().equals(
                                castOther.getTitleDescription())))
                && ((this.getSchoolSearchName() == castOther
                        .getSchoolSearchName()) || (this.getSchoolSearchName() != null
                        && castOther.getSchoolSearchName() != null && this
                        .getSchoolSearchName().equals(
                                castOther.getSchoolSearchName())))
                && ((this.getBoroughDescription() == castOther
                        .getBoroughDescription()) || (this
                        .getBoroughDescription() != null
                        && castOther.getBoroughDescription() != null && this
                        .getBoroughDescription().equals(
                                castOther.getBoroughDescription())))
                && ((this.getDistrict() == castOther.getDistrict()) || (this
                        .getDistrict() != null
                        && castOther.getDistrict() != null && this
                        .getDistrict().equals(castOther.getDistrict())))
                && ((this.getPhone() == castOther.getPhone()) || (this
                        .getPhone() != null && castOther.getPhone() != null && this
                        .getPhone().equals(castOther.getPhone())))
                && ((this.getFileNumber() == castOther.getFileNumber()) || (this
                        .getFileNumber() != null
                        && castOther.getFileNumber() != null && this
                        .getFileNumber().equals(castOther.getFileNumber())))
                && ((this.getMemberGroup() == castOther.getMemberGroup()) || (this
                        .getMemberGroup() != null
                        && castOther.getMemberGroup() != null && this
                        .getMemberGroup().equals(castOther.getMemberGroup())));
    }

    public int hashCode() {
        int result = 17;

        result = 37 * result
                + (getEmail() == null ? 0 : this.getEmail().hashCode());
        result = 37 * result
                + (getMemberId() == null ? 0 : this.getMemberId().hashCode());
        result = 37 * result
                + (getFirstName() == null ? 0 : this.getFirstName().hashCode());
        result = 37 * result
                + (getLastName() == null ? 0 : this.getLastName().hashCode());
        result = 37 * result
                + (getSchoolId() == null ? 0 : this.getSchoolId().hashCode());
        result = 37 * result
                + (getTitleId() == null ? 0 : this.getTitleId().hashCode());
        result = 37
                * result
                + (getTitleDescription() == null ? 0 : this
                        .getTitleDescription().hashCode());
        result = 37
                * result
                + (getSchoolSearchName() == null ? 0 : this
                        .getSchoolSearchName().hashCode());
        result = 37
                * result
                + (getBoroughDescription() == null ? 0 : this
                        .getBoroughDescription().hashCode());
        result = 37 * result
                + (getDistrict() == null ? 0 : this.getDistrict().hashCode());
        result = 37 * result
                + (getPhone() == null ? 0 : this.getPhone().hashCode());
        result = 37
                * result
                + (getFileNumber() == null ? 0 : this.getFileNumber()
                        .hashCode());
        result = 37
                * result
                + (getMemberGroup() == null ? 0 : this.getMemberGroup()
                        .hashCode());
        return result;
    }

}

所以现在我做了一个mvn包,我得到了以下错误:

Tests in error: 
  testgetMemeberRequestInformation(org.uftwf.memberinquiry.test.TestApp): Provided id of the wrong type for class org.uftwf.model.MemberInquiryLookup. Expected: class org.uftwf.model.MemberInquiryLookupId, got class java.lang.String

共有1个答案

汝开畅
2023-03-14

您正在通过hibernate查找请求者,我假定请求者是一个字符串。实体中的id是MemberInquiryLookupID。Hibernate不知道它应该在哪个列上匹配给定的值。

解决办法可以是使用标准API或编写HQL:

FROM MemberInquiryLookup m WHERE m.id.email = :parameter

在我看来,hibernate以不正确的方式对表进行了反向工程。您的数据库中有复合主键吗?如果不是,您一定要修改代码来纠正错误。

 类似资料:
  • null null 但是Hibernate反向工程创建的代码没有任何@entity、@table或@column标记看起来所有的映射都在hbm.xml中。如何在Spring MVC项目中使用它们

  • 主要内容:1. 下载 Hibernate 开发包,2. 新建工程,3. 创建数据库表,4. 创建实体类,5. 创建映射文件,6. 创建 Hibernate 核心配置文件,7. 测试本节我们将演示如何搭建一个 Hibernate 工程。 搭建 Hibernate 工程需要以下 7 步: 下载 Hibernate 开发包 新建工程 创建数据库表 创建实体类 创建映射文件 创建 Hibernate 核心配置文件 测试 1. 下载 Hibernate 开发包 浏览器访问  Hibernate 官网 下载

  • 我正在Eclipse Neon中使用Hibernate工具(JBoss tools 4.4.0.Final)。现在,我想将数据库表反向工程为POJO对象和Hibernate映射文件。 我遵循了一些关于如何设置Eclipse来生成POJO对象的教程。在我运行配置之前,一切看起来都很好。什么都没发生,也没有抛出错误。有人能帮我吗?数据库是一个微软SQL服务器2014。 我的逆向工程配置文件看起来像:

  • 我的Hibernate查询SessionFactory sessionFactory=new Configuration(). confiure(). buildSessionFactory(); sess=sessionFactory.openSession()有问题;我在每个函数中都调用它,我如何避免它只创建一次sessionFactory

  • 使用HiberNate ant任务从Gradle我能够生成实体类从数据库使用留档在http://docs.jboss.org/tools/latest/en/hibernatetools/html_single/index.html#d0e5102 当我更改和时,HiberNate找不到我的自定义模板。可以肯定的是,我直接从hiberNate jars复制了模板,并在Pojo.ftl.中添加了一个

  • 我正在使用Spring Boot,我将向您解释我所进行的过程,然后我将为您暴露我的问题: 我正在使用的数据库是postgres:因为我有一个包含多个表的富数据库,所以我应用了hibernate反向工程来生成hole实体,直到这一步一切都很棒! 问题,在运行项目时,它就像是spring-data JPA和hibernate之间的混淆! ps:在项目开始工作之前,我用一张桌子做了一些实验,它工作得很好