I have an Entity-class (mapped using JPA annotations and some hibernate-annotations, mostly just @CollectionOfElements) that has a persistent java.util.Map field, using a (java 5) enum as the key and a self-defined class as the value (see below). Persisting this in the database works great, but i have the problem that trying to build a query on the map-values creates an exception. The query looks like this:
Code:
EntityManager entityManager; //...
Query query = entityManager.createQuery("select user from User user where user.profile[:nameEnum] = :name");
query.setParameter("nameEnum", ProfileEntryKey.NAME);
query.setParameter("name", "Some Name");
List<User> users = query.getResultList();
The the last line throws an exception with the strange reason "Invalid character string format for type INTEGER" whose stacktrace is reproduced below.
Now my question is: Is this a problem with my mappings? With my query syntax? Or could it be a problem specific to the derby database and its dialect?
Regards,
David
Hibernate versions: Hibernate 3.2.6-GA, Hibernate Annotations 3.3.1.GA, Hibernate EntityManager 3.3.2.GA
Mapped Classes:User.java:
Code:
@Entity
public class User {
public enum ProfileEntryKey {
NAME, // ...
}
// ...
@CollectionOfElements(fetch = LAZY)
public Map<ProfileEntryKey, ProfileEntry> getProfile() {
return profile;
}
}
ProfileEntry.java:
Code:
@Embeddable
public class ProfileEntry {
// ...
@Basic(optional=false)
public String getValue() {
return value;
}
@Enumerated(value=EnumType.ORDINAL)
@Basic(optional=false)
public PrivacyLevel getLevel() {
return level;
}
// ...
}
Full stack trace of any exception that occurs:Code:
[#|2008-06-12T19:19:54.416+0200|SEVERE|
sun-appserver9.1|javax.enterprise.system.container.web|
_ThreadID=20;_ThreadName=httpSSLWorkerThread-8080-1;
_RequestID=4ba1fce4-bf67-4382-9f68-d15c6493f6c9;|
StandardWrapperValve[TestServlet]: PWC1406: Servlet.service() for servlet TestServlet threw exception
javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)
at de.myv.platform.user.TestServlet.testSearch(TestServlet.java:61)
at de.myv.platform.user.TestServlet.doGet(TestServlet.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: org.hibernate.exception.DataException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
... 31 more
Caused by: java.sql.SQLException: Invalid character string format for type INTEGER.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.executeQuery(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
... 39 more
Caused by: org.apache.derby.client.am.SqlException: Invalid character string format for type INTEGER.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.am.Statement.completeOpenQuery(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseOpenQueryFailure(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseOPNQRYreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readOpenQuery(Unknown Source)
at org.apache.derby.client.net.StatementReply.readOpenQuery(Unknown Source)
at org.apache.derby.client.net.NetStatement.readOpenQuery_(Unknown Source)
at org.apache.derby.client.am.Statement.readOpenQuery(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.executeQueryX(Unknown Source)
... 45 more
|#]
Name and version of the database you are using:
Apache Derby Network Server 10.2.2.1 (aka. the JavaDB in Glassfish v2ur1)