0

I have a entity which has a many relationships to other entities like below:

class Customer {

private String email;

// many to many 
private Set<Street> streets

// many to many 
private Set<Address> addresses;

and soo on..
}

I would like to find all customers and get back as a list of Customers with set only an emails - without any sets.

It is possible using query extracted from method name? Or only can I get only a list of objects[] and build objects in service?

1
  • Collections are lazy by default, so as long as you don't access them they aren't filled unless of course you made them eager. Commented Apr 21, 2015 at 11:48

1 Answer 1

1

You should be able to use the IS EMPTY JPQL, as documented here:

@Query("select c from Customer c WHERE c.streets IS EMPTY AND c.addresses IS EMPTY")
List<Customer> findCustomersWithoutRelations();
Sign up to request clarification or add additional context in comments.

1 Comment

Customers in database are have releationship already. I don't want to get list of customer which are not have any streets or addreses. I wanted to get only a main object. After thinking ...it was a stiupid question. Query should get a current state of object in the database. If collections are lazy that should be filled when I want to access to them.

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.