English 中文(简体)
Hibernate note @Many ToMany
原标题:Hibernate annotations @ManyToMany

I created tables in MySQL: role tabel , object_label and role_object_label (links table)

I defined @ManyToMany and I gets exception. what the problem in my code?

@Entity
@Table(name = "object_label")
public class ObjectLabel  implements Serializable {

    private static final long serialVersionUID = 3475812350796110403L;
    private String name;

    1. 长期公共收入(第1款);

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO)
@Column(precision = 10, unique = true, nullable = false, updatable = false)
public Long getId() {
    return id;
}

@Override
public void setId( Long id ) {
    this.id = id;
}

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }


}


@Entity
@Table(name = "role")
public class Role  implements Serializable {

1. 长期公共收入(第1款);

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO)
@Column(precision = 10, unique = true, nullable = false, updatable = false)
public Long getId() {
    return id;
}

@Override
public void setId( Long id ) {
    this.id = id;
}

   @ManyToMany( fetch = FetchType.EAGER )
    @JoinTable(
        name = "role_object_label", joinColumns = @JoinColumn(name = "role_id"), 
        inverseJoinColumns = @JoinColumn(name = "object_label_id"))
    public Set<ObjectLabel> getObjectLabels(){
        return this.objectLabels;
    }

    /**
     * @param objectLabels the objectLabels to set
     */
    public void setObjectLabels(Set<ObjectLabel> objectLabels) {
        this.objectLabels = objectLabels;
    }

    private Set<ObjectLabel> objectLabels = new HashSet<ObjectLabel>();
}

参见:

<mapping class="com.myCompany.model.RoleObjectLabel" />
<mapping class="com.myCompany.model.ObjectLabel" />

我例外:

Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.sintecmedia.model.Role.objectLabels[com.myCompany.model.ObjectLabel]

Thanks! Rivki

问题回答

错误解释,“目标”是指实体类别。

你用@Entity对你的班次做了说明,但你却想说一句话。 @Entity和@Id都必须申报适当的实体类别。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签