hibernate @Entity on inner class only (top level class is not an @Entity)

夙愿已清 提交于 2021-02-07 18:47:54

问题


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);
         }
     }
}

回答1:


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.



来源:https://stackoverflow.com/questions/23008424/hibernate-entity-on-inner-class-only-top-level-class-is-not-an-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!