What is wrong with my HQL query? Does not return the user for a given token (this token in the database is 100%).

HQL

@Query("SELECT u FROM User u inner join u.session s where s.token = :session") User getUserBySession(@Param("session") String session); 

User

 @Entity @Table(name = "\"user\"") public class User{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToOne private Session session; 

Session

 @Entity @Table(name="session") public class Session { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String token; @OneToOne @JoinColumn(name = "userid") private User user; 
  • one
    SELECT u FROM User u inner join u.session s where s.token = :session If the query is valid, then: 1) there is a database named u 2) It has a table called session 3) it has a token field 4) in The current database has a table named User 5) in one of these tables there is a field named u . If at least one of this is incorrect, then the request is also incorrect. - Akina
  • @Akina, if it’s not difficult for you, then please show how the query will look: from the table with the name User, take all the data of the user who has a userid in the Session table, in which the token field is equal to the transmitted token? - helloitsmedog
  • I do not use Hibernate / HQL, but it is lazy to study. Convert HQL-s User and Session in normal SQL - then I will prompt. - Akina

0