Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic JPA issue: "Could not determine type for: java.util.Set"

I'm just getting started building my JPA schema in a Play Framework web app. I have a reasonable understanding of SQL, but I'm a JPA newbie, and I'm being tripped up at the first hurdle.

From the Play tutorials I'm assuming you just create your Java classes and JPA/Play will automagically create the schema for you.

So I want to create a ManyToMany relationship between two model classes, Rankable and Tag:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Rankable extends Model {
    public String name;
    private Set<Tag> tags;

    @ManyToMany()
    @JoinTable(name = "RANKABLE_TAGS")
    public Set<Tag> getTags() {
        return tags;
    }

    @ManyToMany()
    @JoinTable(name = "RANKABLE_TAGS")
    public void setTags(final Set<Tag> tags) {
        this.tags = tags;
    }
}

And the other class:

@Entity
public class Tag extends Model {
    public String name;
    public String description;
    private Set<Rankable> rankables;

    @ManyToMany(mappedBy = "tags")
    public Set<Rankable> getRankables() {
        return rankables;
    }

    @ManyToMany(mappedBy = "tags")
    public void setRankables(final Set<Rankable> r) {
        rankables = r;
    }
}

But I keep getting the following error:

A JPA error occurred (Unable to build EntityManagerFactory): Could not determine type for: java.util.Set, at table: Rankable, for columns: [org.hibernate.mapping.Column(tags)]

What am I doing wrong?

like image 437
sanity Avatar asked Jan 25 '11 18:01

sanity


Video Answer


1 Answers

In our case, the reason was that we had some annotations on the field and some on the getters. In other words, for a specific field, the annotations should be either on the field or on the getter. Combining them on the getters solved the problem for us. Seems like the exception do not show the real cause of the problem. By the way, we used this syntax for the manytomany annotations:

  1. Entity:

    @ManyToMany
    @JoinTable(name = "join_table", joinColumns = { @JoinColumn(name =
    "leftjoinid") }, inverseJoinColumns = { @JoinColumn(name = "rightjoinid") }) 
    
  2. Entity:

    @ManyToMany
    @JoinTable(name = "join_table", joinColumns = { @JoinColumn(name =
    "rightjoinid") }, inverseJoinColumns = { @JoinColumn(name = "leftjoinid") }) 
    
like image 128
ruhsuzbaykus Avatar answered Oct 20 '22 16:10

ruhsuzbaykus