'Using JPA to retrieve particular many-valued association columns

There is a column that's so huge, it slows the entire query speed. So i need to ommit the one, only give when actualy needed. I've tried this solution:

@Query("SELECT new Account (a.name) From Account a Where a.id = :id)

The above code will retrive the id column data.When I try to use other getter,obviously the rest property are all null. but when it comes with other entity relation for example:

//The account entity code
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    @NotFound(action = NotFoundAction.IGNORE)
    private User user;
/**
The user side code is ommitted
**/
@Query("SELECT new Account (a.name,a.user) From Account a)

it will generarte these sql query:

inner join
        user user3_ 
            on account0_.user_id=user3_.id 

However, when we using the normal jpa method like

@Query("SELECT a FROM Account a WHERE a.id = :id")
Account getById(UUID id)

we can easily get the user entity with the getter method:

Account acc = accountRepository.getById(id);
User user = acc.getUser();

Not the inner join sql query;

How can I retrieve the paritcular association entity columns with getter?

Can it be possible to achieve with jpa?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source