How to create meta annotations on field level?

瘦欲@ 提交于 2019-12-04 05:18:25

I think I can aswer your third question.

One common way to do what you want (avoid duplicating ID mapping) is to create a common superclass that holds the annotated id and version (for optimistic locking) fields, and then have all persistent objects extend this superclass. To ensure the superclass is not considered an Entity on its own, it must be annotated with @MappedSuperclass.

Here is a sample (sorry for typos, I don't have an IDE at hand right now) :

@MappedSuperclass
public class PersistentObject {

    @Id // Put all your ID mapping here
    private Long id;

    @Version
    private Long version;

}

@Entity
public class SimpsonsFamily extends PersistentObject {        
    // Other SimpsonFamily-specific fields here, with their mappings    
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!