简体   繁体   English

即使我使用正确的映射在HQL中提供类和实体名称,Hibernate中的querysyntaxexception

[英]querysyntaxexception in Hibernate even if i give class and entity name in HQL with proper mapping

I am working on a hibernate. 我正在休眠。 I am getting below Exception 我低于异常

org.hibernate.hql.ast.QuerySyntaxException: DBCDataSource is not mapped [from DBCDataSource where upper(datasourceType) = upper('BAC_MANAGEMENT')]

I searched in net and got answer as in HQL we need to use class names and property names instead of table and column names. 我在net中搜索并得到了答案,因为在HQL中,我们需要使用类名和属性名而不是表名和列名。 The query was using column name so i have changed it ti use property name after that also exception dint went. 该查询使用的是列名,因此在异常Dint消失之后,我已经更改了它的使用属性名。 I have checked in HIbernate.cfg.xml the for any missing mapping but i found mapping s correct. 我已经在HIbernate.cfg.xml中检查了任何丢失的映射,但是我发现映射正确。 Find ma code below. 在下面找到ma代码。

previous query-->list =  session.createQuery("from DBCDataSource where upper(DATASOURCE_TYPE) = upper('" + type +"')").list();
DATASOURCE_TYPE is a column name

Modified to-->list =  session.createQuery("from DBCDataSource where upper(datasourceType) = upper('" + type +"')").list();
datasourceType is a propery name mapped to tat column.

Entity class 实体类

@Entity
@Table(name="dict_db_ds")
public class DBCDataSource implements Serializable{
.
.
.

@Column(name = "DATASOURCE_TYPE")
    private String datasourceType;

}

Hibernate.cfg.xml Hibernate.cfg.xml

..
..
 <mapping class="com.hp.bto.bsmr.collection.dao.omi.DBCDataSource" /> 
..
..

am i missing further?? 我进一步想念吗?

Kindly advice.. 好心的建议..

Thank you. 谢谢。

You can try this 你可以试试这个

 list =  session.createQuery("from DBCDataSource where "
              +"upper(datasourceType) =:type")
             .setParameter("type", type)
             .list();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.hql.internal.ast.QuerySyntaxException:即使我使用实体的类名,也未映射员工 - org.hibernate.hql.internal.ast.QuerySyntaxException: Employee is not mapped even though i use the class name of the entity 实体未映射 Hibernate org.hibernate.hql.ast.QuerySyntaxException - entity is not mapped Hibernate org.hibernate.hql.ast.QuerySyntaxException 即使我声明映射类,未知实体也会休眠 - Unknown entity hibernate even if I declare mapping class org.hibernate.hql.internal.ast.QuerySyntaxException:实体未映射 - org.hibernate.hql.internal.ast.QuerySyntaxException: Entity is not mapped org.hibernate.hql.ast.QuerySyntaxException:未映射TABLE NAME - org.hibernate.hql.ast.QuerySyntaxException: TABLE NAME is not mapped Hibernate 映射类实体名称 - Hibernate mapping class entity-name 带有Hibernate的org.hibernate.hql.ast.QuerySyntaxException - org.hibernate.hql.ast.QuerySyntaxException with Hibernate org.hibernate.hql.internal.ast.QuerySyntaxException:Hibernate无法映射表名 - org.hibernate.hql.internal.ast.QuerySyntaxException: Hibernate not able to map table name org.hibernate.hql.internal.ast.QuerySyntaxException: <table_name> 未映射[来自 <table_name> ] - org.hibernate.hql.internal.ast.QuerySyntaxException: <table_name> is not mapped [from <table_name>] org.hibernate.hql.ast.QuerySyntaxException - org.hibernate.hql.ast.QuerySyntaxException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM