aggiunto mapping relazione, entity manager da container, listener, callbacks, query

This commit is contained in:
2015-05-10 18:07:41 +02:00
parent 5d21a01bcc
commit e060799a3c
7 changed files with 297 additions and 11 deletions

View File

@@ -22,7 +22,9 @@ import javax.validation.executable.ExecutableValidator;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
@@ -50,7 +52,71 @@ public class Servlettest3 extends HttpServlet {
out.println("<h1>Servlet xg at " + request.getContextPath() + "</h1>");
s.store_class(new test_class() );
s.store_class(new test_class());
out.println(s.find(1L).getTitle());
//s.fake_remove(1L);
s.remove_and_persist(1L);
test_class t = s.find(1L);
t.setTitle("alibaa");
out.println(s.find(1L).getTitle()); // database isn't updated
out.println(s.contains(s.find(1L))); // it's false
s.merge(t);
out.println(s.find(1L).getTitle());// database is updated! All OK!
//test_class q = (test_class) s.namedquery_single("findtest_class") ;
//out.println(q.getTitle());
/*
List<Object> q = s.namedquery_multiple("findtest_class") ;
Iterator<Object> it = q.iterator();
while (it.hasNext()){
out.println(((test_class) it.next()).getTitle());
}
*/
out.println("<br>");
List<Object> q2 = s.dynquery_multiple("SELECT t FROM test_class t") ;
Iterator<Object> it = q2.iterator();
while (it.hasNext()){
out.println(((test_class) it.next()).getTitle());
}
out.println("<br>");
HashMap<String,String> h = new HashMap<String,String>();
h.put("fname", "alibaa");
// h.put(...);
List<Object> q3 = s.dynquery_multiple_string("SELECT t FROM test_class t where t.title = :fname", h) ;
Iterator<Object> it2 = q3.iterator();
while (it2.hasNext()){
out.println(((test_class) it2.next()).getTitle());
}
out.println("<br>");
HashMap<Integer,String> h2 = new HashMap<Integer,String>();
h2.put(1,"alibaa");
// h2.put(...);
List<Object> q4 = s.dynquery_multiple_integer("SELECT t FROM test_class t where t.title = ?1", h2) ;
Iterator<Object> it3 = q4.iterator();
while (it3.hasNext()){
out.println(((test_class) it3.next()).getTitle());
}