如何在没有@id元素的情况下设置@entity? [英] how to set a @entity without @id element?

查看:611
本文介绍了如何在没有@id元素的情况下设置@entity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个bean:

@Entity
@Table(name = "accesos")
public class Acceso implements Serializable {
    /** */
    @Column(name = "idUser")
    private String idUser;
    /** */
    @ManyToOne
    @JoinColumn(name = "idArea")
    private Area area;
    /** */
    @ManyToOne
    @JoinColumn(name = "idRol")
    private Rol rol;

但我收到此错误:


引起:org.hibernate.AnnotationException:没有为entity指定标识符:com ... Acceso

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com...Acceso

我怎样才能设置这个bean?我需要的是基于用户ID获取他有权访问的所有ROL-AREA。

How can I set this bean? What I need is based on the user ID get all the ROL-AREA that he has access.

我尝试更改 @Entity @Embedded ,但是当我进行搜索时没有返回结果,甚至在日志中也没有执行SQL语句。

I tried change the @Entity to @Embedded, but when I make the search no result is returned, and even in the log is no SQL sentence executed.

推荐答案

你必须拥有每个bean的身份,没有办法解决。但是,如果您的字段都不是唯一的,则可以使用组合密钥。

You have to have an identity for each bean, there is no way around. You can however use a combined key, if none of your fields is unique.

如果所有字段的组合都是唯一的,则尝试注释所有字段 @Id 。尽可能少的字段,但需要尽可能多的字段使组合独特。

If the combination of all your fields is unique, then try to annotate all fields with @Id. Take as few fields as possible, but as many as required to make the combination unique.

这篇关于如何在没有@id元素的情况下设置@entity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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