我用的是myEclipse5.5.1的插件package cn.com.test.hibernatesample.test;import java.beans.Expression;
import java.util.List;import junit.framework.Assert;
import junit.framework.TestCase;import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;import cn.com.test.hibernatesample.factory.HibernateSessionFactory;
import cn.com.test.hibernatesample.model.User;/**
* @author Administrator
*
*/
public class UserTest extends TestCase { // hibenate的session对象
private Session session = null; protected void setUp() throws Exception {
super.setUp();
session = HibernateSessionFactory.getSession();
} public void testCriteria() {
Transaction tran = null;
tran = session.beginTransaction();
Criteria criteria = session.createCriteria(User.class);
criteria.add(Expression.eq("id", new Integer(1)));
//报the method eq(String,Integer) is undefined for the type Expression
//为什么这个函数会找不到?类Expression是存在的,求助
List crit=criteria.list();
Iterator iter = crit.iterator();
while(iter.hasNext()){
User user=(User) iter.next();
System.out.println(user.getName());
}
} protected void tearDown() throws Exception {
super.tearDown();
HibernateSessionFactory.closeSession();
}}
import java.util.List;import junit.framework.Assert;
import junit.framework.TestCase;import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;import cn.com.test.hibernatesample.factory.HibernateSessionFactory;
import cn.com.test.hibernatesample.model.User;/**
* @author Administrator
*
*/
public class UserTest extends TestCase { // hibenate的session对象
private Session session = null; protected void setUp() throws Exception {
super.setUp();
session = HibernateSessionFactory.getSession();
} public void testCriteria() {
Transaction tran = null;
tran = session.beginTransaction();
Criteria criteria = session.createCriteria(User.class);
criteria.add(Expression.eq("id", new Integer(1)));
//报the method eq(String,Integer) is undefined for the type Expression
//为什么这个函数会找不到?类Expression是存在的,求助
List crit=criteria.list();
Iterator iter = crit.iterator();
while(iter.hasNext()){
User user=(User) iter.next();
System.out.println(user.getName());
}
} protected void tearDown() throws Exception {
super.tearDown();
HibernateSessionFactory.closeSession();
}}
解决方案 »
- extjs bbar iconCls 请问这个图标怎么加载进来呀
- 求助,查询mysql数据。模糊查询查不到数据
- javax.servlet.ServletException: Class servlets.LoginServlet is not a Servlet
- 请教tomcat中有关service方法的问题
- struts的页面为什么都是.do为后缀的呢?
- 服务器端发生错误:Cannot create JDBC driver of class '' for connect URL 'null'
- 关于struts配置的问题
- JBOSS中如何配置虚拟目录(virtual directory)?
- 求优秀的java web 架构的项目源码?(抱歉,没分了)
- ssm电商项目bug请求大佬们
- java 事件响应问题
- java中如何比较时间段
确认下是否是对应包下的Exception
只是不知道为什么网上还是书上都是可以直接调用的
唉
hibernate里面有用到的,这个你可以参考下hibernate的Expression类