Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:18:37+00:00 2026-05-24T09:18:37+00:00

I am using the Play Framework in it’s current version and my model classes

  • 0

I am using the Play Framework in it’s current version and my model classes extend play.db.jpa.JPABase.

Today I tried to make an often used type of query generic and define a static helper method to construct 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:

Execution exception

UnsupportedOperationException occured : Please annotate your JPA model with @javax.persistence.Entity annotation.

I debugged into the method, at runtime T seems to be correctly set to it’s corresponding Model class. I even see the annotation.

I suspect some class enhancing voodoo by the play guys responsible for this, but I am not entirely sure.

Any ideas?

Update: added Model class as Requested

Here is a shortened Version of one of the Model classes 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();
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:18:38+00:00Added an answer on May 24, 2026 at 9:18 am

    In Play entites should extend play.db.jpa.Model and use @Entity annotation (class level).

    For what you say I understand that you are extending play.db.jpa.JPABase.

    This may be the reason of the issue, as Play (as you point) dynamically enhances classes and it may be clashing with your inheritance.

    EDIT: I tested the issue

    The problem is that Play is not enhancing the object T. This means that the find method called id the one of GenericModel (parent of Model) whose implementation is to throw an exception with the message.

    The enhancer seems to detect only the classes with @Entity.

    Even the solution of mericano1 doesn’t work, the enhancer doesn’t pick it. So I feel you won’t be able to use that method in Play.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JPA through the Play Framework. I'm checking to see if a User
I'm using the Play! framework and I have a model (an Entity) that has
iam using AVFoundation Framework to play mp3 file ,everything works great ، i have
I am using the AVAudioPlayer framework, and I have several sounds that play one
I'm learning using Play Framework and doing a demo app for it. For this
I am using the MediaPlayer framework to play a movie on the iPhone. There
How can I play a movie in my app? I tried using this code,
In play framework application.conf there are lines: %test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0 %test.jpa.ddl=create But I am using MongoDB
I'm developing a web service using Play Framework. My next step is to log
I have a small site I built using the Play framework that I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.