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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With