Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inner join in play framework ebean

I have a query which i want to write in my Product model

select * from shop inner join product on product.shops_id=shop.id where product.name=keyword

Shop.java

public class Shop extends Model {

    @Id
    @SequenceGenerator(name="shop_gen", sequenceName="shop_id_seq", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="shop_gen")
    @Column(name="id")
    public Long id;

    @Required
    public String name;

    @Required
    public String addressLine1;

    public String addressLine2;

    public String addressLine3;

    @Required
    public String city;

    @Required
    public String town;

    @Required
    public String phoneNumber;

    @OneToMany(mappedBy = "shops",cascade = CascadeType.REMOVE)
    public List<Product> products=new ArrayList<>();


    @Required
    @OneToOne
    public String category;

    @Lob
    @Column(name = "shop_pic")
    public  byte[] shop_pic;


    @ManyToOne
    @Required
    public User owner;

}

Product.java

public class Product extends Model {
   @Id
    @SequenceGenerator(name="product_gen", sequenceName="product_id_seq", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="product_gen")
    @Column(name="id")
    public Long id;
    @Required
    public String name;
    @Required
    public Float price;
    @OneToOne
    @Required
    public String category;
    @ManyToOne
    public Shop shops;
}

My main aim is to find list of shops which has a particular product.

where keyword change everytime. i have referred to similar question but dint understand any of them. Any help would be appreciated

like image 430
akku Avatar asked Nov 10 '22 08:11

akku


1 Answers

With proper relations in your models it would be:

Shop.find.where().like("product.name", keyword).findList();

Anyway we don't know nothing about your models.

like image 71
biesior Avatar answered Nov 14 '22 23:11

biesior