在Hibernate中更新和保存单个查询

时间:2018-02-08 07:57:34

标签: java mysql hibernate

我想更新父表,同时在hibernate中的单个自定义查询中将数据保存在子表中。 这是我的服务实现。

Post::where('id', $post->id)->update($request->all());

这是查询文件(保存customQuery):

public int updateTimeTable(Map<String, Object> timeTable) {
    int rows = timeTableDao.updateTimeTable(timeTable);
    if(rows>2) {
        rows = temptimeTableDao.updateTempTimeTable(timeTable);
    }
    return rows;
}

updateTimeTable查询:

public int updateTempTimeTable(Map<String, Object> map) {
    Query query = customQuery("Insert into temp_time_table(employee_id,duration_till,duration_from,timetable_id)"
            + " values(:employeeId, :durationStart,:durationEnd,:timetableId)");
    query.setLong("employeeId", Long.parseLong(map.get("employeeId").toString()));
    query.setString("durationStart", map.get("durationStart").toString());
    query.setString("durationEnd", map.get("durationEnd").toString());
    query.setLong("timetableId", Long.parseLong(map.get("timetableId").toString()));

    return query.executeUpdate();
}

0 个答案:

没有答案