![]() |
| |||||||||||||||||||
| Resin 3.1 Documentation Examples Changes Quercus Database Amber EJB SOA/ESB IoC JMS Servlet JMX Hessian Security Field Property Create Query Many-to-One One-to-Many Many-to-Many Inherit Sessions |
The Amber Query API resembles the JDBC PreparedStatement with enhanced SQL and direct support for objects. Files in this tutorial
Database Schema@Entity public class House { @Id@Column(name="id") public long getId() @Basic public String getName() @OneToMany(targetEntity=Student.class, mappedBy="house") public Collection getStudentList() } @Entity public class Student { @Id@Column(name="id") public long getId() @Basic public String getName() @ManyToOne@JoinColumn(name="house") public House getHouse() } Query
private void doService(PrintWriter out)
throws java.io.IOException
{
Query allHouse = _entityManager.createQuery("SELECT o FROM House o");
String sql = ("SELECT s" +
" FROM House h, IN(h.studentList) s" +
" WHERE h.id=?1 AND s.gender='M'");
Query boysInHouse = _entityManager.createQuery(sql);
List houses = allHouse.getResultList();
for (int i = 0; i < houses.size(); i++) {
House house = (House) houses.get(i);
out.println("<H3>Boys living in " + house.getName() + ":</H3>");
boysInHouse.setParameter(1, new Long(house.getId()));
List boys = boysInHouse.getResultList();
if (boys.size() == 0)
out.println("No boys are living in " + house.getName());
for (int j = 0; j < boys.size(); j++) {
Student boy = (Student) boys.get(j);
out.println(boy.getName() + "<br>");
}
}
}
}
| |||||||||||||||||||