求一sql 语句用hibernate 的Criteria 怎么写?

2019-03-25 13:46|来源: 网路

请问以下生成的sql 语句用hibernate 的Criteria 怎么写
传入两参数 Long pid, Long userId
                    StringBuffer sql = new StringBuffer();
		  sql.append("select * from BASEAUTH  ");
		  sql.append(" where AUTHPID= ? and DELETEFLAG =0  ");  		           sql.append(" and ISFUN=0  ");
		
		 sql.append(" and AUTHID IN(");
		 sql.append(" select AUTHID from BASEROLEAUTH where ROLEID in "); 
		 sql.append(" (select ROLEID from BASEROLEUSER  where USERID=? ) ");
		 sql.append(" union");
		 sql.append(" select AUTHID from BASEUSERAUTH where USERID=?"); 
		 
		 sql.append(")");

问题补充: 谢了。。。。
ethen 写道
Criteria criteria =session.createCriteria(BASEAUTH.class);
Criterion criterion2 = Exdivssion.eq("pid",new Long(21));
criteria.add(criterion2);
就是类似上面这种,你试试吧。

相关问答

更多
  • 在hibernate的query 接口查询出一个list后 list里有两个方法 list.setFirstResult(int a); list.setMaxSize(int a); 第一个方法用来设置当前页要显示的第一条记录是从哪一个记录开始的 第二个方法用来设置每页的最大记录数 通过这个就足以实现分页了,先实现了功能再说吧,这样做反正是不太好呵呵
  • 把它归结为1个查询是非常困难的(即我不知道一个可移植的解决方案),但将其归结为2个查询(不论n)是非常简单的: Criteria criteria = this.getSession().createCriteria(Mother.class); criteria.addOrder(Order.asc("title")) .setMaxResults(details.getMaxRows()) .setFirstResult(details.getStartResult()) .se ...
  • 使用hinsnate标准的连接如下面的示例代码: List cats = session.createCriteria(Cat.class) .createAlias("kittens", "kit") .add( Restrictions.like("kit.name", "Iz%") ) .list(); 注意:上面的代码只是如何在hibernate标准中使用Join的示例。 Use Joins using hibernate criteria as below exa ...
  • 我使用Spring AOP做了这样的事情,所以我可以抓住应用程序中运行的任何查询的sql,参数,错误和执行时间,无论是HQL,Criteria还是本机SQL。 这显然是脆弱的,不安全的,随着Hibernate等的变化而变化,但它说明了可以获得SQL: CriteriaImpl c = (CriteriaImpl)query; SessionImpl s = (SessionImpl)c.getSession(); SessionFactoryImplementor factory = (SessionFac ...
  • hibernate文档说: 通过使用createCriteria()导航关联,您可以在相关实体上指定约束: List cats = sess.createCriteria(Cat.class) .add( Restrictions.like("name", "F%") ) .createCriteria("kittens") .add( Restrictions.like("name", "F%") ) .list(); 转换到你的问题: Criteria crit ...
  • 你可以这样做以下任何一种方式。 1)让你查询它并使用nativeSQL进行休眠。 hibernate本机查询,计数 2)制作所有连接表的模型并放入hibernate查询。 You can do it Either of following way. 1) Keep you query as it and use nativeSQL for hibernate. hibernate native query, count 2) make model of all your join table and put ...
  • 给这个镜头: DetachedCriteria d = DetachedCriteria.forClass(QueryDetailEntity.class, "qd"); d.setProjection(Projections.projectionList().add(Projections.property("qd.query"))); d.add(Restrictions.or(Restrictions.like("qd.value1", "PROMPT%"), Restrictions.like("q ...
  • 好的从头开始..你的实体类应该是这样的: @Entity @Table(name="TOPIC_USERS") public class UserTopics { @Id @GeneratedValue(strategy= GenerationType.IDENTITY) @Column(name="TOPICUSER_ID") private Integer id; @Column(name="USER_ID") private Integer user ...
  • 这样的东西应该工作 - 用相应的限制替换'is null'和'in'表达式 criteria.conjuction() .add(USER_TERM_DT is null ) .add(criteria.disjuction(). add( criteria.conjuction() .add(ROLE_ID in (101,102) ) ...
  • 没有开箱即用的方法来执行此操作,因为sqlRestriction仅解释表达式{alias},但没有表达式来获取别名的表名。 但是,您可以从Hibernate / Entity元数据中查找表名,然后将其插入到sqlRestriction中(使用一些不太不受欢迎的字符串连接)。 您需要使用此处描述的方法之一创建自己的实用程序类以从实体类获取tablename: 从Hibernate中的模型中获取表名 There's not an out of the box way to do this because sql ...