仅在内部类上休眠@Entity(顶级类不是@Entity) [英] hibernate @Entity on inner class only (top level class is not an @Entity)

查看:92
本文介绍了仅在内部类上休眠@Entity(顶级类不是@Entity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将内部类持久化到数据库中.但这没有用. 有这样做的可能性吗?还是应该将该内部类放入新的纯文件中? 现在我遇到了错误

 [IllegalArgumentException: Unknown entity: models.foo$bar] 

我的班级文件:

package models;
public class foo {
     @Required public String report;
     @Required public String reportType;


     @Entity
     public static class bar{
         @Required public int year;
         @Required public int month;

         public void toDataBase() {
                JPA.em().persist(this);
         }
     }
}

解决方案

引用JPA 2.1规范:

实体类必须是顶级类.枚举或接口不得指定为实体

您可以从此地址下载规范. 可以在此处中很好地描述了可以映射为实体的内容.. >

I would like to persist inner class into database. But it dosnt work. Is there possibilty to do that? Or should i put that inner class into new plain file? Now I am getting an error

 [IllegalArgumentException: Unknown entity: models.foo$bar] 

My class file:

package models;
public class foo {
     @Required public String report;
     @Required public String reportType;


     @Entity
     public static class bar{
         @Required public int year;
         @Required public int month;

         public void toDataBase() {
                JPA.em().persist(this);
         }
     }
}

解决方案

Quoting JPA 2.1 specification:

The entity class must be a top-level class. An enum or interface must not be designated as an entity

You can download the spec from this address. What can be mapped as an entity is as well pretty well described here.

这篇关于仅在内部类上休眠@Entity(顶级类不是@Entity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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