public class StudentDao {
public Student queryStudentbyId(EntityManager entitymanager,Integer id){
return entitymanager.createNamedQuery("studentInfoById", Student.class).setParameter(1, 1).getSingleResult();
}
public class StudentDao {
public static final String deleteStudentId = "delete from student_info where stu_id = ? ";
public static final String updateStudentId = " update student_inf set stu_name = ? where stu_id = ? ";
public void deleteStudentById(EntityManager entitymanager,Integer id ){
entitymanager.createNativeQuery(deleteStudentId).setParameter(1, id).executeUpdate();
}
public void updateStudentById(EntityManager entitymanager,Integer id ){
entitymanager.createNativeQuery(updateStudentId).setParameter(1, id).executeUpdate();
}
@Entity
@NamedNativeQuery(name="queryCourseInfoByid",
query = " select course_id,course_name,stu_id from course_info where course_id = ? ",
resultSetMapping = "courseInfo"
)
@SqlResultSetMapping(name="courseInfo",entities=@EntityResult(entityClass=Course.class))
@Table(name="course_info")
public class Course {
public class CourseDao {
public Course queryCouserInfoById(EntityManager entityManager,Integer id ){
return entityManager.createNamedQuery("queryCourseInfoByid", Course.class).setParameter(1, id).getSingleResult();
}
}
那么在执行本地查询的时候,查询的时候会根据外键列,查询关联实体,这样会发送两次查询
最好设置实体中关联对象的字段为懒加载。需要注意缓存的是外键列的值。
CourseDao dao = new CourseDao();
Course course = dao.queryCouserInfoById(entityManager, 1);
打印SQL:
Hibernate:
select
course_id,
course_name,
stu_id
from
course_info
where
course_id = ?
Hibernate:
select
student0_.stu_id as stu_id1_19_0_,
student0_.stu_sex as stu_sex2_19_0_,
student0_.stu_age as stu_age3_19_0_,
student0_.stu_name as stu_name4_19_0_
from
student_info student0_
where
student0_.stu_id=?
@SuppressWarnings("unchecked")
public List querystudentJoinCourse(EntityManager entitymanager,Integer stuId,Integer courseId){
List list = entitymanager.createNamedQuery("studentJoinCourse").setParameter(1, stuId).setParameter(2, courseId).getResultList();
return list;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml&q
// for循环的进化
// 菜鸟
for (var i = 0; i < Things.length ; i++) {
// Things[i]
}
// 老鸟
for (var i = 0, len = Things.length; i < len; i++) {
// Things[i]
}
// 大师
for (var i = Things.le
the idea is from:
http://blog.csdn.net/zhanxinhang/article/details/6731134
public class MaxSubMatrix {
/**see http://blog.csdn.net/zhanxinhang/article/details/6731134
* Q35
求一个矩阵中最大的二维
使用cordova可以很方便的在手机sdcard中读写文件。
首先需要安装cordova插件:file
命令为:
cordova plugin add org.apache.cordova.file
然后就可以读写文件了,这里我先是写入一个文件,具体的JS代码为:
var datas=null;//datas need write
var directory=&
SELECT cust_id,
SUM(price) as total
FROM orders
WHERE status = 'A'
GROUP BY cust_id
HAVING total > 250
db.orders.aggregate( [
{ $match: { status: 'A' } },
{
$group: {