HQL在onetoMany中保持连接状态

时间:2015-11-26 11:37:10

标签: hibernate spring-boot oracle-sqldeveloper spring-data-jpa

任命和转移表与onetomany关系。

SQL查询以查找约会日为星期六的所有班次详细信息 即使没有约会,也要显示所有班次。

// this query works in sql developer
select * from TEST_SHIFTS s LEFT OUTER JOIN TEST_APPOINTMENT2 a
   ON s.SHIFT_NUMBER = a.SHIFT_ID and a.APP_DAY='Sat'

HQL查询:

@Query("Select s FROM Shifts s LEFT JOIN s.appointments a with a.APP_DAY='Sat'")

@Query("Select s FROM Shifts s LEFT JOIN s.appointments a on a.APP_DAY='Sat'")

@Query("Select s FROM Shifts s LEFT JOIN s.appointments a on s.shiftId = a.shifts and a.APP_DAY='Sat'")

以上hql查询都没有提供所需的结果。

以下是使用的两个实体:

@Entity
@Table(name="TEST_APPOINTMENT2")
public class NewAppointment {

    @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Column(name="Appoint_Id")
    private int appointmentId;

     @ManyToOne
     @JoinColumn(name="shiftId")
    // @JsonBackReference
     //@JsonIgnore
     private Shifts shifts;
.....    
}


@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="shiftId",scope=Shifts.class)
@Table(name="TEST_SHIFTS")

public class Shifts {

    @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Column(name="ID")
     private int shiftId;


     @OneToMany(mappedBy="shifts" )
//   @JsonManagedReference
//   @JsonIgnore
     private List<NewAppointment> appointments;

.....

}

0 个答案:

没有答案