Getting <Model> is not mapped when doing JPA query

4,038 views
Skip to first unread message

John Pletka

unread,
Jul 1, 2011, 2:06:21 AM7/1/11
to play-fr...@googlegroups.com
When I run:
JPA.em().query("select s from Statistic s ")

it throws the exception:
org.hibernate.hql.ast.QuerySyntaxException: Statistic is not mapped
[select s from Statistic s ]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)

But when I run:
but when I run Statistic.all().fetch()
it works fine.

Is there there anything special I need to do to get JPA queries to
work? The Statistic model does extend a base model, and there is a
package-level filterDef applied to the base model.

Manuel Bernhardt

unread,
Jul 1, 2011, 5:14:01 AM7/1/11
to play-fr...@googlegroups.com
How is Statistic defined? Do you perhaps use a configuration which
would lead Hibernate to look for the full package name rather than
just the entity?

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

John Pletka

unread,
Jul 1, 2011, 9:35:13 AM7/1/11
to play-fr...@googlegroups.com
I've tried using models.Statistic also, but it did not work.

package models;
@Entity(name="statistics")
public class Statistic extends MTAModel{ ... }

@MappedSuperclass
@Filter(name="tenant")
public abstract class MTAModel extends AuditableModel { ... }

@MappedSuperclass
public abstract class AuditableModel extends play.db.jpa.Model { ... }

@FilterDef(name="tenant", parameters= { @ParamDef( name="tenant_id",
type="long") }, defaultCondition=" (tenant_id = :tenant_id OR
tenant_id = -1)" )
package models;

public class MultiTenant extends Controller {
@Before
public static void setFilters() {
Tenant tenant = Tenant.current();
if(tenant != null){
((Session) JPA.em().getDelegate()).enableFilter("tenant").setParameter("tenant_id",
tenant.id);

Manuel Bernhardt

unread,
Jul 1, 2011, 1:33:04 PM7/1/11
to play-fr...@googlegroups.com
> package models;
> @Entity(name="statistics")
> public class Statistic extends MTAModel{ ... }

here you are changing the name of the entity so I guess your query
should go like:

"SELECT s from statistics s where ..."

if you want to change the table name you need to use @Table(name = ...)

Reply all
Reply to author
Forward
0 new messages