try {
sessionOracle = BaseDAO.getHibernateSession().openSession();
sessionPostgres = BaseDAOgis.getHibernateSession().openSession();
int id = 0;
JSONArray jaRoute = new JSONArray();
for (int i = 0; i < dataHolder.size(); i++) {
JSONObject jo = new JSONObject();
try{
jo.put("routeNo", (int) list.get(0));
jo.put("routeName", list.get(1).toString());
jo.put("stopSequenceID", (int) list.get(2));
jo.put("stopID", (int) list.get(3));
jo.put("stopName", list.get(4).toString());
jo.put("lat", (double) list.get(5));
jo.put("lon", (double) list.get(6));
System.out.println(jo.length() + "" +cellStoreVector.size());
if(jo.length()!=cellStoreVector.size())
{
System.out.println(jo.length() + "if" +cellStoreVector.size());
joOutput.put("success", true);
joOutput.put("error", true);
joOutput.put("size", false);
return joOutput;
}
}
catch(Exception e){
System.out.println("EXCEWs");
System.out.println(e);
joOutput.put("success", true);
joOutput.put("error", true);
joOutput.put("size", false);
return joOutput;
}
jaRoute.put(jo);
}
System.out.println("DB");
txPostgres = sessionPostgres.beginTransaction();
txOracle= sessionOracle.beginTransaction();
for (int i = 0; i < jaRoute.length(); i++) {
direction = "U";
JSONObject first = jaRoute.getJSONObject(i);
routeNo = first.getString("routeNo");
System.out.println();
int no = Integer.parseInt(routeNo);
routeName = first.getString("routeName");
stopSequenceID = first.getString("stopSequenceID");
stopID = first.getString("stopID");
stopName = first.getString("stopName");
lat = first.getString("lat");
lon = first.getString("lon");
if(i < jaRoute.length() - 1)
second = jaRoute.getJSONObject(i + 1);
System.out.println("id"+ id);
if(Integer.parseInt(first.getString("routeNo"))!= id){
try{
String sqlRouteMaster = "insert into route_master(route_id, route_name, direction, route_status, route_no, ROUTE_EFCTV_FROM_DT,Source_stop_id,dest_stop_id,ROUTE_TYPE,city_operational) "
+ "values('"
+ routeNo
+ "','"
+ routeName
+ "','"
+ direction1
+ "','"
+ routeStatus
+ "','"
+ routeName.trim().substring(0, 9)
+ "',now(),'"+1038+"','"+1039+"','"+37+"','"+false+"')";
String sqlMRoute="insert into m_route(route_id, route_name, direction, route_status, route_no, ROUTE_EFCTV_FROM_DT,source_stop_id, dest_stop_id,ROUTE_TYPE,CITY_TYPE) "
+ "values('"
+ routeNo
+ "','"
+ routeName
+ "','"
+ direction
+ "','"
+ routeStatus
+ "','"
+ routeName.trim().substring(0, 9)
+ "', current_timestamp,'"+1038+"','"+1039+"','"+37+"','"+97+"')";
int list4=sessionPostgres.createSQLQuery(sqlRouteMaster)
.executeUpdate();
System.out.println(list4);
int list5=sessionOracle.createSQLQuery(sqlMRoute).executeUpdate();
System.out.println(list5);
}catch(Exception ii){
}finally{}
if(Integer.parseInt(second.getString("routeNo")) == id || id == 0){
double endLat = Double.parseDouble(second
.getString("lat"));
double endLon = Double.parseDouble(second
.getString("lon"));
theGeom = getMultiLineString(startLat, startLon,
endLat, endLon);
if (theGeom.length() > 0) {
System.out.println("rout");
sqlRouteDetails = "insert into route_details(route_seq_no,route_id,stop_seq_no,stop_id,location,lat,lon,the_geom,stop_type_id,REF_DISTANCE,REF_TIME,STOP_TIME)"
+ " values('"
+ routSeqNo
+ "','"
+ routeNo
+ "','"
+ stopSequenceID
+ "','"
+ stopID
+ "','"
+ stopName
+ "','"
+ lat
+ "','"
+ lon
+ "',ST_SetSRID(ST_GeomFromText('"
+ theGeom
+ "'),4326),'"
+ stopTypeId
+ "','"
+ refDistance
+ "','" + refTime + "','" + stopTime + "')";
} else {
System.out.println(id);
sqlRouteDetails = "insert into route_details(route_seq_no,route_id,stop_seq_no,stop_id,location,lat,lon,stop_type_id,REF_DISTANCE,REF_TIME,STOP_TIME)"
+ " values('"
+ routSeqNo
+ "','"
+ routeNo
+ "','"
+ stopSequenceID
+ "','"
+ stopID
+ "','"
+ stopName + "','" + lat + "','" + lon + "','"+stopTypeId+"','"+refDistance+"','"+refTime+"','"+stopTime+"')";
}
id=Integer.parseInt(first.getString("routeNo"));
String sqlMRouteDtl="insert into m_route_dtl(route_seq_no,route_id, stop_seq_no, stop_id,stop_type_id,REF_DISTANCE,REF_TIME,STOP_TIME) "
+ "values('"+mRouteSql+"','"+routeNo+"','"+stopSequenceID+"','"+stopID+"','"+stopTypeId+"','"+refDistance+"','"+refTime+"','"+stopTime+"')";
sessionPostgres.createSQLQuery(sqlRouteDetails).executeUpdate();
sessionOracle.createSQLQuery(sqlMRouteDtl).executeUpdate();
routSeqNo++;
}
//
txOracle.commit();
//
txPostgres.commit();
joOutput.put("success", true);
joOutput.put("error", false);
} catch (Exception i) {
i.printStackTrace();
//
txPostgres.rollback();
//
txOracle.rollback();
joOutput.put("success", false);
joOutput.put("error", false);
} finally {
try {
sessionPostgres.close();
sessionOracle.close();
} catch (Exception e) {
e.printStackTrace();
}
return joOutput;
}
}
第一次或两次,appLicaton运行正常,但如果我们正在尝试下次它被卡住
Hibernate: insert into m_route(route_id, route_name, direction, route_status, route_no, ROUTE_EFCTV_FROM_DT,source_stop_id, dest_stop_id,ROUTE_TYPE,CITY_TYPE) values(?,?,?,?,?,?,?,?,?,?,?)
我们再次重新启动Oracle数据库然后再次重复。一次或两次跑步和卡住。 请帮我。 提前致谢。 我无法找到问题所在。为什么锁定/ postgres和oracle。
route_master和route_details是Postgres表和 m_route和m_route_dtl 是Oracle表
答案 0 :(得分:1)
首先,为什么在项目中使用Hibernate时使用普通的sql?它效率不高。
第二个基于你提供的每次打开新的hibernate会话的代码,尝试只启动它一次。
最后你可以在oracle / postgres上登录管理员帐户并检查apllication被卡住时实际发生了什么吗?