mandubian/siena — Issue #7: Filter by enum value on Postgres
Author: joshx
Created: 2011-10-19 08:39:58+00:00
State: open

I encountered the following issue on Postgres:

Here is my model class:

public class User extends Model {
public static enum UserRole {
SUPPORT,
ADMIN,
STAFF
};
@Id(Generator.AUTO_INCREMENT)
public Long id;
@Column("user_role")
public UserRole role;
[...]
}

In my controller, I want to get the list of users with user role
"STAFF". So I wrote:

List users = models.User.all().filter("role",
models.User.UserRole.STAFF).fetch();

This works on GAE. But it fails on Postgres resulting in an exception,
which I have appended at the end.

In an attempt to solve the issue, I found that calling name() on the
enum value works both for Postgres and GAE:

List users = models.User.all().filter("role",
models.User.UserRole.STAFF.name()).fetch();

--------------------------

SienaException occured : org.postgresql.util.PSQLException: The used
data type in SQL for an instance of models.User$UserRole could not be
derived. Please use 'setObject()' with an explicit type in order to
define it.
play.exceptions.JavaExecutionException:
org.postgresql.util.PSQLException: The used data type in SQL for an
instance of models.User$UserRole could not be derived. Please use
'setObject()' with an explicit type in order to define it.
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:229)
at Invocation.HTTP Request(Play!)
Caused by: siena.SienaException: org.postgresql.util.PSQLException:
The used data type in SQL for an instance of models.User$UserRole
could not be derived. Please use 'setObject()' with an explicit type
in order to define it.
at
siena.jdbc.JdbcPersistenceManager.doFetch(JdbcPersistenceManager.java:
668)
at
siena.jdbc.JdbcPersistenceManager.fetch(JdbcPersistenceManager.java:
719)
at siena.BaseQuery.fetch(BaseQuery.java:115)
at controllers.Fallakten.list(Fallakten.java:112)
at
play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:546)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:500)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:476)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:471)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:159)
... 1 more
Caused by: org.postgresql.util.PSQLException:The used data type in SQL
for an instance of models.User$UserRole could not be derived. Please
use 'setObject()' with an explicit type in order to define it.
at
org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statemen t.java:
1805)
at
org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gState ment.java:
37)
at
org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statemen t.java:
46)
at
siena.jdbc.PostgresqlPersistenceManager.setParameter(PostgresqlPersistenceM anager.java:
40)
at
siena.jdbc.JdbcPersistenceManager.createStatement(JdbcPersistenceManager.ja va:
270)
at
siena.jdbc.JdbcPersistenceManager.doFetch(JdbcPersistenceManager.java:
628)
... 9 more