java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException:

时间:2018-04-11 15:27:32

标签: java hibernate

java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException:Application_Identity(类名)未映射[来自Application_Identity(类名)]

我在使用HQL

获取数据时遇到此错误

所涉及的类和文件如下所示

Application_Identity类

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;


@SuppressWarnings("serial")
@Entity
public class Application_Identity implements Serializable
{
@Id
@Column(columnDefinition = "serial")

private long Application_ID;

public long getApplication_ID() {
    return Application_ID;
}

public void setApplication_ID(long application_ID) {
    Application_ID = application_ID;
}


}

这里Application_Identity是父类,其他类具有一对一的关系

hibernate.cfg.xml文件

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">babaswami</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cola?useSSL=true</property>
        <property name="hibernate.connection.username">himanshu</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="hibernate.hbm2ddl.auto">create</property> 
        <property name="show_sql">true</property>
        <!-- Mapping files -->
        <mapping resource="Application_Identity.hbm.xml"/>
        <mapping resource="Application_Type.hbm.xml"/>
        <mapping resource="Graduation.hbm.xml"/>
        <mapping resource="Other_Details.hbm.xml"/>
        <mapping resource="Other_Qualifications.hbm.xml"/>
        <mapping resource="Personal_Details.hbm.xml"/>
        <mapping resource="Phd.hbm.xml"/>
        <mapping resource="Post_Graduation.hbm.xml"/>
        <mapping resource="Sslc_Puc.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

其他课程

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;



@SuppressWarnings("serial")
@Entity
public class Application_Type implements Serializable
{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long application_type_id;
    private String applicant_type;
    @OneToOne(cascade=CascadeType.ALL,targetEntity=Application_Type.class)
    private Application_Identity application_identity;

    public long getApplication_type_id() {
        return application_type_id;
    }
    public void setApplication_type_id(long application_type_id) {
        this.application_type_id = application_type_id;
    }
    public String getApplicant_type() {
        return applicant_type;
    }
    public void setApplicant_type(String applicant_type) {
        this.applicant_type = applicant_type;
    }
    public Application_Identity getApplication_identity() {
        return application_identity;
    }
    public void setApplication_identity(Application_Identity application_identity) {
        this.application_identity = application_identity;
    }

}

2 个答案:

答案 0 :(得分:0)

尝试添加:

 @Table(name="Application_Identity_TABLE_NAME") 
如果名称是不同的,则

到您的实体..您能显示表结构吗?

答案 1 :(得分:0)

为了确保您的实体正确映射,请尝试为您的实体执行此操作:

@Entity 
@Table(name="TABLE_IN_DATABASE_NAME")
public class EntityClass implements Serializable { 
    @Id 
    @Columns(name="ID")
    private Integer id;

    @Columns(name="OTHER_INT") //same column name in the table
    private Integer otherInt;
    //getters setters 
} 

PS:更改私有的Application_ID;私人长期application_ID;