简体   繁体   中英

Hibernate Enum Set Error

I have a Role object which holds several permissions(which are ENUM). But i keep getting this error.

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

What is the best way to represent.

Role Class:

@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;
    }
    ....
}

hibernate.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>

在权限集上尝试@ElementCollection。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM