java sql语句大于小于,具有大于或小于hibernate命名的sql查询

I'm using hibernate 3 with named query in the hibernate configuration xml.

The named query originally matched a date with the user entered date, and it worked fine.

But when I changed the equals ('=') to a less than ('<=') it gave me the following error.

Caused by: org.hibernate.MappingException: Could not parse mapping document in input stream

at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:431)

at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)

... 106 more

Caused by: org.dom4j.DocumentException: Error on line 57 of document : The content of elements must consist of well-formed character data or markup. Nested exception: The content of elements must consist of well-formed character data or markup.

at org.dom4j.io.SAXReader.read(SAXReader.java:482)

at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)

... 107 more

This is because the XML parser does not allow '' inside the content of tags. But '' is necessary to form the <= or >= comparison. Is there an alternate way to represent greater than or less than such that the parser is happy.

NB: I already know we can put the named query as annotation in the code, but I prefer it this way for system consistency.

Sample Named Query:

SELECT person.NAME AS {person.name},

person.AGE AS {person.age},

person.SEX AS {person.sex}

FROM PERSON person

WHERE person.NAME LIKE :namePattern

AND trim(person.JOINDATE) <= to_date(:joinDate, 'dd-mm-yyyy')

解决方案

Use CDATA or < to escape < in xml.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值