猿问

休眠表未映射但表存在

我有一个使用Hibernate的项目,但有一个错误表未映射。


org.jboss.resteasy.spi.UnhandledException: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TrainingRoom is not mapped [SELECT DISTINCT t FROM TrainingRoom t ORDER BY t.id]

at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:77)

at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:220)

at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:175)

...

Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TrainingRoom is not mapped [SELECT DISTINCT t FROM TrainingRoom t ORDER BY t.id]

at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187)

at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)

at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327)

...

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: TrainingRoom is not mapped [SELECT DISTINCT t FROM TrainingRoom t ORDER BY t.id]

at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)

at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)

at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)

...

这是我的TrainingRoom.java


@Entity

@Table(name = "ppp_trainingRoom")

public class TrainingRoom {


    @Id

    @GeneratedValue(strategy = GenerationType.TABLE)

    @Column(name = "id", updatable = false, nullable = false)

    private Long id;


    @Column

    private String roomName;


    //GET SET Method


}

在遇到这个错误之前,我有2个EntityManager,因为我有一些同义词表。但是我发现它不是必须的。所以我删除了它,然后卡住了,就像上面的错误一样。


我该如何解决?


慕哥9229398
浏览 178回答 1
1回答

有只小跳蛙

您可以添加新属性:&nbsp;<property&nbsp;name="hibernate.archive.autodetection"&nbsp;value="class"&nbsp;/>或者,您可以在持久性单元标签下为每个类指定类标签:<class>org.cmh.itsetup.model.TrainingRoom</class>
随时随地看视频慕课网APP

相关分类

Java
我要回答