1

我有一个 Role 对象,它拥有多个权限(即 ENUM)。但我不断收到这个错误。

Use of @OneToMany or @ManyToMany targeting an unmapped class: objects.Role.permissions[enums.AgentPermission]

什么是最好的代表方式。

角色等级:

@Entity
@Table(name="\"Role\"")
public class Role {
    @Id
    @GeneratedValue
    private int id;
    @ManyToOne
    private Company company;
    private String name;
    @ManyToMany
    private Set<AgentPermission> permissions;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    ....
}

休眠.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- hibernate dialect -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
....    
        <mapping class="objects.Role" />
        <mapping class="objects.Tag" />
....    
    </session-factory>
</hibernate-configuration>
4

1 回答 1

1

在您的权限集上尝试 @ElementCollection。

于 2015-11-21T00:23:37.877 回答