Java 如何为oracle执行标准查询
如何重新生成此代码以与oracle配合使用。在此之前,它与博士后合作,没有错误。现在它给出了sql语法错误Java 如何为oracle执行标准查询,java,oracle,hibernate,criteria,Java,Oracle,Hibernate,Criteria,如何重新生成此代码以与oracle配合使用。在此之前,它与博士后合作,没有错误。现在它给出了sql语法错误 public List<MyOrder> myOrderListNew(Company company){ Criteria criteria = session.getCurrentSession().createCriteria(MyOrder.class); criteria.add(Restrictions.eq("company.id
public List<MyOrder> myOrderListNew(Company company){
Criteria criteria = session.getCurrentSession().createCriteria(MyOrder.class);
criteria.add(Restrictions.eq("company.id", company.getId()));
criteria.add(Restrictions.eq("removeorder", false));
criteria.add(Restrictions.eq("status", "new"));
criteria.addOrder(Order.desc("id"));
List<MyOrder> myOrders = criteria.list();
return myOrders;
}
已格式化,您使用的查询如下。我已经标记了似乎错误的内容:列名不能是
DATE
或SUM
,因为它们是保留字(用于数据类型和函数)
怎么办?取决于表说明。如果您成功创建了这样一个表,那么必须将列名括在双引号中。如果是这样的话,那么每次使用这些列时都必须执行相同的操作,例如
SQL> create table myorder
2 ("DATE" date,
3 "SUM" number
4 );
Table created.
SQL> -- this is what you are currently doing; see? The same ORA-01747 error
SQL> select this_.date,
2 this_.sum
3 from myorder this_;
select this_.date,
*
ERROR at line 1:
ORA-01747: invalid user.table.column, table.column, or column specification
SQL> -- this is what you should be doing
SQL> select this_."DATE",
2 this_."SUM"
3 from myorder this_;
no rows selected
SQL>
如果可能,更改列名以使您的生活更轻松
SELECT this_.myOrder_id AS myOrder_id1_6_0_,
this_.myorder_company_id AS myorder_company_id9_6_0_,
this_.courier_id AS courier_id10_6_0_,
this_.date AS date2_6_0_, --> this
this_.date_hms AS date_hms3_6_0_,
this_.hide AS hide4_6_0_,
this_.removeorder AS removeorder5_6_0_,
this_.selected AS selected6_6_0_,
this_.shops_id AS shops_id11_6_0_,
this_.status AS status7_6_0_,
this_.SUM AS sum8_6_0_ --> this
FROM myorder this_
WHERE this_.myorder_company_id = :1
AND this_.removeorder = :2
AND this_.status = :3
ORDER BY this_.myOrder_id DESC
SQL> create table myorder
2 ("DATE" date,
3 "SUM" number
4 );
Table created.
SQL> -- this is what you are currently doing; see? The same ORA-01747 error
SQL> select this_.date,
2 this_.sum
3 from myorder this_;
select this_.date,
*
ERROR at line 1:
ORA-01747: invalid user.table.column, table.column, or column specification
SQL> -- this is what you should be doing
SQL> select this_."DATE",
2 this_."SUM"
3 from myorder this_;
no rows selected
SQL>