Posts Tagged ‘java’

Hibernate Annotations examples and reference

Found a really great reference with examples of Hibernate association mappings using annotations.
http://tadtech.blogspot.com/2007/09/hibernate-association-mappings-in.html

Hibernate HQL like query using named parameters

Using the LIKE condition with a “%” sign for pattern matching in a HQL query with named parameters required some tweaking.
This did not work:

String query = "from user u where u.name like %:name%"

getHibernateTemplate().findByNamedParam(query, "name", str);

It resulted in a org.hibernate.QueryException: unexpected char: ‘%’ error.
Next I tried using single quotes:

String query = "from user u where u.name [...]

I18n workaround for Spring form:options tag

Spring Framework provides the convenient form:options tag to render a list of <option> tags for a form <select>. Here is an example:

<form:select id="status" path="status" cssClass="text large" cssErrorClass="text large error" >
<form:options items="${statusList}" itemValue="id" itemLabel="label"></form:options>
</form:select>

It does iteratate through statusList and will output each item as an option with the value statusList[i].id and the [...]