Wrong hibernate generation query with left join two table with spring boot 3 and hibernate 6

230 views Asked by At

I'm woriking on the project with springboot for backend. I have an issue usiny @Query with left join when updating spring boot ver2 to ver3 In my project have used @Inheritance(strategy = InheritanceType.SINGLE_TABLE) and @DiscriminatorColumn - @DiscriminatorValue for table parent and child. The query used has "left join" another table with child table (extend parent table)

  • In springboot ver2 when hibernate generate query have not condition of discriminator was added
  • But in springboot ver3 the condition of discriminator was added.

Exp:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "tbl_accounts")
@DiscriminatorColumn(name="account_type")
public class Account {

   ...
   @Enumerated(EnumType.STRING)
   @Column(name="account_type", updatable=false, insertable = false)
   protected String accountType
}
@Entity
@DiscriminatorValue("STUDENT")
@DynamicUpdate
@OptimisticLocking(type = OptimisticLockType.DIRTY)
public class StudentAccount extends Account {

  ...
  @Column(name = "student_code", columnDefinition = "varchar(50)")
    private String studentCode;
}

@Entity
@Table(name = "tbl_configuration_information_student")
public class InformationStudentConfiguration {
  ...
  @Column(name = "student_code", unique = true)
  protected String studentCode;
}

And the @Query

@Query("select new InformationStudentConfigurationDto(c.id, c.studentCode, sa.name, c.date) " +
            "from InformationStudentConfiguration c left join StudentAccount sa on " +
            "c.studentCode= pa.studentCode")

Hibernate generate: in Sp ver2 : Hibernate: select t1_0.id,t1_0.studentCode,p1_0.name,t1_0.date from tbl_configuration_information_student t1_0 left join tbl_accounts p1_0 on t1_0.student_code=p1_0.student_code

in Sp ver3 : Hibernate: select t1_0.id,t1_0.studentCode,p1_0.name,t1_0.date from tbl_configuration_information_student t1_0 left join tbl_accounts p1_0 on t1_0.student_code=p1_0.student_code where p1_0.account_type='STUDENT'

In the example above, How to ignore p1_0.account_type='STUDENT' in spring boot ver3 when hibernate generates this query?

I tried query with "left outer join" but hibernate still generated condition p1_0.account_type='STUDENT'

0

There are 0 answers