SQL错误:933,SQLState:42000和ORA

系统教程 行业动态 更新时间:2024-06-14 16:58:30
SQL错误:933,SQLState:42000和ORA-00933:SQL命令未正确结束(SQL Error: 933, SQLState: 42000 and ORA-00933: SQL command not properly ended)

我正在使用Hibernate进行数据库访问。 我在我的代码中使用以下查询来获取我需要的数据:

SELECT proasset FROM com.company.claims.participant.AbstractBeneficiary bene JOIN bene.approvals approval JOIN bene.proassetkey proasset join proasset.relatedparties proassetparties WHERE approval.user_dt > :currentDate AND approval.user_type = :userType

我在下面使用它作为query :

Query q = this.getSessionFactory().getCurrentSession().createSQLQuery(query.toString()) q.setDate("currentDate", new Date()); q.setString("userType", APPROVER_USER_TYPE); List<ProAsset> proassets = q.list();

但是,在尝试运行它时会遇到以下情况:

SQL Error: 933, SQLState: 42000 ORA-00933: SQL command not properly ended

如果重要,则使用StringBuilder构造查询,并使用\n来分隔行

有关这个问题的任何想法?

I'm using Hibernate for database access. I'm using the following query in my code to fetch the data I need:

SELECT proasset FROM com.company.claims.participant.AbstractBeneficiary bene JOIN bene.approvals approval JOIN bene.proassetkey proasset join proasset.relatedparties proassetparties WHERE approval.user_dt > :currentDate AND approval.user_type = :userType

I'm using it as query in the following:

Query q = this.getSessionFactory().getCurrentSession().createSQLQuery(query.toString()) q.setDate("currentDate", new Date()); q.setString("userType", APPROVER_USER_TYPE); List<ProAsset> proassets = q.list();

However, I encounter the following when trying to run it:

SQL Error: 933, SQLState: 42000 ORA-00933: SQL command not properly ended

If it matters, the query is being constructed using a StringBuilder and it uses \n to break the lines

Any thoughts on the problem?

最满意答案

看起来您正在尝试将ORM与本机(普通旧SQL)查询混合使用。

createSQLQuery需要本机SQL。 您正在使用类而不是表名。 试试这个:

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html

简而言之,您需要编写如下查询:

select fu from bar where situation = 'snafu'

也许你真的想写一个namedQuery? 他们使用ORM语法来加入实体,就像您在示例中所做的那样。

检查这些例子:

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html#querysql-namedqueries

It looks like you are trying to mix ORM with a native (plain old SQL) query.

createSQLQuery requires native SQL. You are using classes instead of table names. Try a read of this:

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html

In short you need to write a query like:

select fu from bar where situation = 'snafu'

Perhaps you are really wanting to write a namedQuery? They use ORM syntax where you join entities as it seems you are doing in your example.

Check these examples out:

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html#querysql-namedqueries

更多推荐

本文发布于:2023-04-15 03:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/eb57a2065d4838c4a16e57479643814e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   SQL   ORA   SQLState

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!