JPA main problem: "Could not determine type for: java.util.Set"

I am just starting to build my JPA scheme in the Play Framework web application. I have a reasonable understanding of SQL, but I'm new to JPA, and I'm getting off the first hurdle.

From the Play tutorials, I assume that you just create your Java classes, and JPA / Play will automatically create a schema for you.

So, I want to create ManyToMany relationships 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 another 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:

JPA error occurred (EntityManagerFactory cannot be built): Could not determine type for: java.util.Set, at table: Rankable, for columns: [Org.hibernate.mapping.Column (tags)]

What am I doing wrong?

+7
source share
3 answers

In the end, this seemed to work, although I'm not sure why:

 @Entity public class Tag extends Model { public String name; public String description; @ManyToMany(mappedBy = "tags", cascade = CascadeType.ALL) public Set<Rankable> rankables; } 

and

 @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Rankable extends Model { @ManyToOne(cascade = CascadeType.ALL) public User creator; public String name; @ManyToMany() public Set<Tag> tags; } 
+2
source

In our case, the reason was that we had some annotations on the field, and some on getters. In other words, for a particular field, annotations must be either on the field or on the getter. Combining them with getters solved the problem for us. It seems that the exception does not show the real cause of the problem. By the way, we used this syntax for manytomany annotations:

  • Entity:

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

     @ManyToMany @JoinTable(name = "join_table", joinColumns = { @JoinColumn(name = "rightjoinid") }, inverseJoinColumns = { @JoinColumn(name = "leftjoinid") }) 
+7
source

It seems that @ManyToMany not taking effect.

Perhaps this is a mess with the placement of annotations. Make sure your getters have the appropriate setters ( setTags() ), and all other annotations are also placed in the properties (not in the fields).

0
source

All Articles