Paweł Opiela
Paweł Opiela

Reputation: 23

Play 2.3 Ebean, @OneToMany relation with join

I have two classes as below.

@Entity 
public class A extends Model 
{ 
   @Id
   private Long id;
   private String value; 

   @OneToMany(targetEntity = AB.class, mappedBy = "a", cascade=CascadeType.ALL) 
   private List<AB> ab;
}

@Entity 
public class AB extends Model 
{ 
   @Id
   private Long id;

   @ManyToOne(targetEntity = A.class) 
   private A a; 

   private Integer type;
}

I want to get all A objects related to AB object where type for example is set to 3.

List<A> aList = A.find.where().join("AB").where().eq("AB.type", "3").findList();  

And in result I have error:

[RuntimeException: Error getting BeanDescriptor for path join ajoin_b from models.A]

I was trying everythings, @JoinTable, @JoinColumn etc

I know that I can do it in directly by sql, by I want to know what is wrong with this code.

Upvotes: 2

Views: 1173

Answers (1)

Shanness
Shanness

Reputation: 395

Try this

A.find.fetch("ab").where().eq("t1.type", 3).findList();

The t1 got me for a while, but the generated SQL seemed to make the join table clear. I'm using PostgreSQL. I don't think you need to quote the 3, as AB.type is an integer (int in the DB).

This might work too.

A.find.where().eq("ab.type",3).findList()

Upvotes: 1

Related Questions