Hibernate / JPA for many relationships through a connection table and composite key, a problem with a unique constraint

So, I asked this question yesterday, but the goal messages have changed, and the question is different:

Hibernate / JPA A collection of elements with many for many relationships.

I want to know if it is possible to create objects that will simulate my required relationships so that Hibernate creates my schema when my application starts.

The relationships I want are as follows:

1 http://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash4/417593_10150594114269218_505554217_8657377_1475865815_n.jpg

The fact is that the Join table may contain rows that are not associated with any element. The structure is a categorization of elements based on a pair of "type" and "value" and is introduced into the system outside this particular application.

What I would like to do is set my Hibernate Entity element so that it contains a list of categories through matching so that I can really see which categories my element belongs to. And so hibernate creates a table for me.

Here is what I have so far: matching this in my Element Entity class is as follows:

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "ELEMENT_ELEMENTCATOGORY", joinColumns = {
        @JoinColumn(name = "type", referencedColumnName = "type"),
        @JoinColumn(name = "value", referencedColumnName = "value") })
@Column(name = "category")
public List<ElementCategory> getCategories() {
    return categories;
}

, , , , , , , , (, ). , , , , ? " "?

+5
1

, Hibernate .

@ManyToMany, joincolumns . , , hibernate , ElementCategory value type. . hibernate , ElementType

, Element ElementType, , joincolumns

+1

All Articles