我正在List使用 hibernate 保存 a ,但它会引发以下异常:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
Run Code Online (Sandbox Code Playgroud)
我正在使用的代码如下,但我不知道为什么它会引发异常:
public void save(List<UserItem> list)
{
//getHibernateTemplate().saveOrUpdateAll(list);
//getHibernateTemplate().deleteAll(list);
sessFactory = getHibernateTemplate().getSessionFactory();
Session session = sessFactory.getCurrentSession();
for (UserItem bean : list) {
session.saveOrUpdate(bean);
}
}
Run Code Online (Sandbox Code Playgroud)
正确的保存方法是什么List?
这是jsonObject的字符串
{"no":1000,"name":"xxx","code":345}
Run Code Online (Sandbox Code Playgroud)
我想将此字符串转换为JSONObject。在这里编码
try {
URL url = new URL("http://localhost:8090/search?numer="+no);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output ;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);//output:{"no":1000,"name":"xxx","code":345}
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)