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 '<' or '>' inside the content of tags. But '<' or '>' 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:
<sql-query name="persons">
<return alias="person" class="eg.Person"/>
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')
</sql-query>