0

JpaRepository

public interface SessionsStoreRepository extends JpaRepository<SessionsStore, Integer> {

SessionsStore findBySessionId(String sessionId);

//JPQL
@Query(value = "SELECT s.username,s.loginTime,s.logoutTime, e.firstName, e.lastName from SessionsStore s, Employee e "
        + " where e.username = s.username and s.isActive= 1")
List<ActiveSession> findUsers();           
}

ActiveSession

import java.time.LocalDateTime;
import lombok.Data;

@Data
public class ActiveSession {

    private String username;
    private String firstName;
    private String lastName;
    private LocalDateTime loginTime;
    private LocalDateTime logoutTime;
}

How can I store the data fetch by @Query(...) in ActiveSession Object Or is there any other way? I tried storing data into object (i.e List<Object>) but I'm using ftl for view and it does not allow you fetch the data unless the object have getters.

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

you can use a class-based projection to achive this.

More information here, or there is a good example of how to use it here

thordickinson
  • 51
  • 1
  • 2