I use the Play Framework in the current version, and my model classes extend play.db.jpa.JPABase.
Today I tried to make the commonly used request type general and define a static helper method to create it.
I wrote the following:
import play.db.jpa.Model; import play.libs.F; public class GenericQueries { public static <T extends Model> F.Option<T> firstOption( Class<T> clazz, String query, Object... parameters){ final T queryResult = T.find(query,parameters).first(); return (queryResult == null) ? F.Option.<T>None() : F.Option.Some(queryResult); } }
However, I get the following error:
Runtime exception
Unsupported OperationException: Please annotate your JPA model using the @ javax.persistence.Entity annotation.
I am debugging a method, at runtime T seems to be correctly set to the corresponding Model class. I even see the annotation.
I suspect some voodoo enhancing class is responsible for the players responsible for this, but I'm not quite sure.
Any ideas?
Update: added model class as requested
Here is an abridged version of one of the Model classes that I use.
package models; import org.apache.commons.lang.builder.ToStringBuilder; import play.data.validation.Required; import play.db.jpa.Model; import play.modules.search.Field; import play.modules.search.Indexed; import javax.persistence.Column; import javax.persistence.Entity; import java.util.Date; @Entity @Indexed public class FooUser extends Model { @Required public Date firstLogin; @Field @Required(message = "needs a username") @Column(unique = false,updatable = true) public String name; @Field public String description; @Required public boolean isAdmin; @Override public String toString(){ return new ToStringBuilder(this) .append("name", name) .append("admin", isAdmin) .toString(); } }
source share