Why is “hibernate.connection.autocommit = true” not recommended in Hibernate?

All database statements are executed within the context of a physical transaction, even when we don’t explicitly declare transaction boundaries (BEGIN/COMMIT/ROLLBACK). If you don’t declare the transaction boundaries, then each statement will have to be executed in a separate transaction. This may even lead to opening and closing one connection per statement. Declaring a service … Read more

How to update XML using XPath and Java

Use setNodeValue. First, get a NodeList, for example: myNodeList = (NodeList) xpath.compile(“//MyXPath/text()”) .evaluate(myXmlDoc, XPathConstants.NODESET); Then set the value of e.g. the first node: myNodeList.item(0).setNodeValue(“Hi mom!”); More examples e.g. here. As mentioned in two other answers here, as well as in your previous question: technically, XPath is not a way to “update” an XML document, but … Read more

What does it mean when Statement.executeUpdate() returns -1?

As the statement executed is not actually DML (eg UPDATE, INSERT or EXECUTE), but a piece of T-SQL which contains DML, I suspect it is not treated as an update-query. Section 13.1.2.3 of the JDBC 4.1 specification states something (rather hard to interpret btw): When the method execute returns true, the method getResultSet is called … Read more

How to set and check cookies wih JAX-RS?

You can do the following: To store a new cookie: @GET @Path(“/login”) @Produces(MediaType.TEXT_PLAIN) public Response login() { NewCookie cookie = new NewCookie(“name”, “123”); return Response.ok(“OK”).cookie(cookie).build(); } To retrieve the cookie (javax.ws.rs.core.Cookie): @GET @Path(“/foo”) @Produces(MediaType.TEXT_PLAIN) public Response foo(@CookieParam(“name”) Cookie cookie) { if (cookie == null) { return Response.serverError().entity(“ERROR”).build(); } else { return Response.ok(cookie.getValue()).build(); } } However, … Read more