1:如果你知道一个实体对象的id,那么就可以用find方法到数据库里加载这个对象。例:
cat = em.find(Cat.class, catId);
2:使用代理对象
child = new Child();
child.SetName("Henry");
Parent parent = em.getReference(Parent.class, parentId); //no query to the DB
child.setParent(parent);
em.persist(child);
3:返回迭代器
Iterator results = em.createQuery(
"select cat.color, min(cat.birthdate), count(cat) from Cat cat " +
"group by cat.color")
.getResultList()
.iterator();
while ( results.hasNext() ) {
Object[] row = results.next();
Color type = (Color) row[0];
Date oldest = (Date) row[1];
Integer count = (Integer) row[2];
.....
}
使用iterator()之后,迭代器里每个对象都是一个数组。
4: