Reputation: 21
I'm using JPA with hibernate and have some trouble with the following JPQL query :
final Query query = getEntityManager().createQuery(
"select u from User u where u.username = :username")
query.setParameter("username", "a");
When using a DB2 V9.7 database the query leads to a NoResultException even though a user with username 'a' exists. This problem only occurs if the column with the username has the type char. If i change the column type to varchar, like hibernate would generate it by himself, the query works fine.
Any ideas?
Enclosed some configuration information :
@Column(name = "USER_NAME", length = 50) @NotNull @Size(max = 50) private String username;
@TypeDef(name = "trimmedString", defaultForType = String.class, typeClass = TrimmedStringUserType.class)
Upvotes: 1
Views: 1805
Reputation: 776
Hibernate maps String to VARCHAR type. This is explained here
http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/types.html
To make sure it maps to char you need to specify in your custom db2 dialect as mentioned here.
JPA/Hibernate DDL generation; CHAR vs. VARCHAR
Upvotes: 0