我在Mysql中查询了下面提到的两个以上的连接,
StringBuilder str_Resource=new StringBuilder();
str_Resource.append("SELECT * FROM BUS_TRANSPORT.TRIP_CALENDAR JOIN BUS_TRANSPORT.ROUTE_MASTER ON BUS_TRANSPORT.TRIP_CALENDAR.ROUTE_CODE=BUS_TRANSPORT.ROUTE_MASTER.ROUTE_CODE ");
str_Resource.append("JOIN BUS_TRANSPORT.TRIP_RESOURCE_ALLOCATOR ON BUS_TRANSPORT.TRIP_CALENDAR.TRIP_ID=BUS_TRANSPORT.TRIP_RESOURCE_ALLOCATOR.TRIP_ID ");
str_Resource.append("JOIN BUS_TRANSPORT.DRIVER_CALENDAR ON BUS_TRANSPORT.DRIVER_CALENDAR.EMP_ID=BUS_TRANSPORT.TRIP_RESOURCE_ALLOCATOR.EMP_ID AND ");
str_Resource.append("BUS_TRANSPORT.DRIVER_CALENDAR.TRIP_ID=BUS_TRANSPORT.TRIP_RESOURCE_ALLOCATOR.TRIP_ID ");
str_Resource.append("JOIN BUS_TRANSPORT.VEHICLE_CALENDAR ON BUS_TRANSPORT.VEHICLE_CALENDAR.VEHICLE_ID =BUS_TRANSPORT.TRIP_RESOURCE_ALLOCATOR.VEHICLE_ID AND ");
str_Resource.append("BUS_TRANSPORT.VEHICLE_CALENDAR.TRIP_ID =BUS_TRANSPORT.TRIP_RESOURCE_ALLOCATOR.TRIP_ID ");
str_Resource.append("JOIN BUS_TRANSPORT.EMP_MASTER ON BUS_TRANSPORT.EMP_MASTER.EMP_ID=BUS_TRANSPORT.DRIVER_CALENDAR.EMP_ID ");
str_Resource.append("JOIN BUS_TRANSPORT.VEHICLE_MASTER ON BUS_TRANSPORT.VEHICLE_MASTER.VEHICLE_ID=BUS_TRANSPORT.VEHICLE_CALENDAR.VEHICLE_ID ");
str_Resource.append("where BUS_TRANSPORT.TRIP_CALENDAR.trip_from_date_time >= NOW() and BUS_TRANSPORT.TRIP_CALENDAR.trip_from_date_time <= (DATE_ADD(NOW(), INTERVAL 6 DAY)) ");
ResultSet resourceAllRS=stmt.executeQuery(str_Resource.toString());
while (resourceAllRS.next()){
JSONObject obj=new JSONObject();
obj.put("rCode", resourceAllRS.getString("ROUTE_CODE"));
obj.put("rName", resourceAllRS.getString("ROUTE_NAME"));
obj.put("source", resourceAllRS.getString("source"));
obj.put("destination", resourceAllRS.getString("destination"));
obj.put("tripStartDate", CommonFunctions.dateConvert(resourceAllRS.getString("TRIP_FROM_DATE_TIME").toString()) );
obj.put("tripstartTime", CommonFunctions.timeConvert(resourceAllRS.getString("TRIP_FROM_DATE_TIME").toString()));
obj.put("tripEndDate", CommonFunctions.dateConvert(resourceAllRS.getString("TRIP_TO_DATE_TIME").toString()));
obj.put("tripEndTime", CommonFunctions.timeConvert(resourceAllRS.getString("TRIP_TO_DATE_TIME").toString()));
obj.put("driverId", resourceAllRS.getString("EMP_ID"));
obj.put("driverName", resourceAllRS.getString("EMP_NAME"));
obj.put("vehId", resourceAllRS.getString("VEHICLE_ID"));
obj.put("vehicleType", resourceAllRS.getString("BUS_TYPE"));
obj.put("tripId", resourceAllRS.getString("TRIP_ID"));
array.put(obj);
System.out.println("obj is "+obj);
}
我已经完成了对hibernate查询的简单查询转换。我将所有pojo类绑定到表。请指导我如何将多个连接查询转换为一个hibernate查询。
答案 0 :(得分:-1)
不是在hibernate中进行连接查询,而是可以以编程方式处理它,因为你有表的pojo类。