在playframework的子模块中添加jpa / hibernate @Entity到实体管理器进行扫描 [英] Adding jpa/hibernate @Entity in submodule in playframework to entity manager to scan

查看:231
本文介绍了在playframework的子模块中添加jpa / hibernate @Entity到实体管理器进行扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用playframework中的子模块时遇到了hibernate实体的问题。

I have problem with hibernate entity while working with submodules in playframework.

通常(在没有子模块的单个应用程序中)我使用了该代码:

Normally (in single app without submodules) I've used that code:

package models;
    @Entity
    public class AppMode {
        public static AppMode getCurrentConfigurationEntry() {
            return JPA.em().find(AppMode.class, 1L);
        }
    }

但现在我必须告诉hibernate实体经理扫描子模块模型,因为我收到错误:

But now I have to tell hibernate entity manager to scan submodules models, cause I'm getting an error:

[IllegalArgumentException: Unknown entity: AppMode]

我在子模块中的模型类在包中:

My model class in submodule is in package:

package models.common;

我已经尝试过:

        return JPA.em().find(models.common.AppMode.class, 1L);
        return JPA.em().find(common.models.AppMode.class, 1L);

但我收到同样的错误:

[IllegalArgumentException: Unknown entity: models.common.AppMode]

我的问题是:如何在play子项目中配置hibernate以在运行时将子模块类添加到类路径?

My question is: How to configure hibernate in play subproject to add submodules models class to classpath at runtime?

我在两个build.sbt文件中都声明了libraryDependencies with hibernate。

I have in both build.sbt files declared libraryDependencies with hibernate.

我是否应该为每个模块设置persistence.xml文件/配置?

Should I have persistence.xml file/configuration for each module?

推荐答案

我必须手动添加映射思想xml persistance文件并使用注释映射:@Entity

I have to mannually add mapping thought xml persistance file and also using Annotation Mapping: @Entity

这篇关于在playframework的子模块中添加jpa / hibernate @Entity到实体管理器进行扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆