0

I have a Class which has other objects as it's members fields. e.g.:

class Orders{
    private Integer code;
    @OneToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="code", nullable=false)
    private Category category;
    private PaymentType pt; 
}

class Category{
    private Integer id;
    @OneToMany(fetch=FetchType.EAGER)
    @JoinColumn(name="id", nullable=false)
    private Brands brand;
    ....
}

class Brands{
    private Integer id;
    private String brandName; 
}

I need to get all the Brands for that particular order.

How do I get just the brands through Orders table in Hql?

1 Answer 1

1

Are the relations one-to-one? If so, you should be able to query it with:

@Query("SELECT FROM Orders orders.category.brand WHERE ...")
Brands findBrandBy(...);

if you are using Spring data.

Sign up to request clarification or add additional context in comments.

3 Comments

The relations are mapped many to one, one to one accordingly. And I'm using Spring mvc
I was thinking of a way where I can use the query in a repo instead of on top of the getter.
This example is meant to be put in spring repository, my method name might be misleading. As for many to one relations there shouldn't be any problems, just return List<Brands> from method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.