criteria

Hibernate: getting too many rows

痞子三分冷 提交于 2019-12-01 03:44:41
问题 I have problem with getting rows from my database using Hibernate. When I would like to get only one row, I am receiving 20. When I would like to get all of rows from table with about 1.5k rows, I am receiving exactly 15.2k rows. Entity class of this table has composite primary key. This is my code for getting all rows: Criteria criteria = getSession().createCriteria(type); criteria.setCacheable(true).setCacheRegion(BaseEntity.PACKAGE); criteria.list(); And this is my Entity class: @javax

How to use MySQL functions in Propel

为君一笑 提交于 2019-12-01 03:07:55
问题 I want to select records that are 1 month old or newer. The query is: SELECT * FROM foobar WHERE created_at > DATE_SUB(curdate(), INTERVAL 1 MONTH) Using Propel in Symfony, I do: $c = new Criteria $c->add(FoobarPeer::CREATED_AT, "DATE_SUB(curdate(), INTERVAL 1 MONTH)", Criteria::GREATER_THAN); What Propel generates is: SELECT * FROM foobar WHERE created_at > 'DATE_SUB(curdate(), INTERVAL 1 MONTH)' - in other words, it puts the MySQL function in single quotes, which makes it a (meaningless)

SSM项目-医药采购-06 数据字典

送分小仙女□ 提交于 2019-12-01 02:10:02
在系统中创建一个张记录数据字典类型: 数据字典类型表 创建一张表记录数据字典明细: 数据字典明细表 将上边变化灵活的配置项叫做:“普通配置项” 将上边固定的配置项(每个配置顶都有一个代码):“业务代码” 普通配置项存储: 普通配置项名称存储在DICTINFO表中info字段 普通配置项对应的类型id存储在DICTINFO表中TYPECODE 业务代码存储: 业务代码对应的名称存储在DICTINFO表中info字段 业务代码对应的类型id存储在DICTINFO表中TYPECODE 业务代码存储在DICTINFO表中DICTCODE(是和普通配置顶的区别) 2、数据字典的使用 3、 小结 普通配置项:对业务数据进行简单的归类,这些归类受用户要求变化较灵活,将这些配置项作普通配置项配置数据字典表。 业务代码:系统运行所必须的,在系统设计时定义的固定代码,这些代码可能需要在程序代码进行硬编码。 4、系统中的应用 public List findDictinfoByType (String typecode) throws Exception { DictinfoExample dictinfoExample = new DictinfoExample(); DictinfoExample.Criteria criteria = dictinfoExample.createCriteria(

Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria

旧巷老猫 提交于 2019-12-01 01:57:24
问题 I'm running into an issue with adding JOIN's to a subquery using DetachedCriteria. The code looks roughly like this: Criteria criteria = createCacheableCriteria(ProductLine.class, "productLine"); criteria.add(Expression.eq("productLine.active", "Y")); DetachedCriteria subCriteria = DetachedCriteria.forClass(Model.class, "model"); subCriteria.setProjection(Projections.rowCount()); subCriteria.createAlias("model.modelLanguages", "modelLang"); subCriteria.createAlias("modelLang.language", "lang"

JPA Criteria API: query property of subclass

删除回忆录丶 提交于 2019-12-01 01:05:19
问题 I have a class structure like this: @Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class Article { private String aBaseProperty; } @Entity public class Book extends Article { private String title; } @Entity public class CartItem { @ManyToOne(optional = false) public Article article; } I tried the following to receive all CartItems that have a reference to a Book with title = 'Foo' : CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<CartItem> query =

NHibernate 2.1: LEFT JOIN on SubQuery with Alias (ICriteria)

你说的曾经没有我的故事 提交于 2019-11-30 21:18:42
I am basically trying to create this query with NHibernate ICriteria interface: SomeTable 1:n AnotherTable SomeTable has columns: PrimaryKey, NonAggregateColumn AnotherTable has columns: PrimaryKey, ForeignKey, AnotherNonAggregate, YetAnotherNonAggregate SELECT table1.NonAggregateColumn, subquery.SubQueryAggregate1, subquery.SubQueryAggregate2 FROM SomeTable AS table1 LEFT JOIN ( SELECT table2.ForeignKey, COUNT(table2.AnotherNonAggregate) AS SubQueryAggregate1, AVG(table2.YetAnotherNonAggregate) AS SubQueryAggregate2 FROM AnotherTable AS table2 GROUP BY (table2.ForeignKey) ) AS subquery ON

Grails/Hibernate: how to order by isnull(property) to get NULLs last?

江枫思渺然 提交于 2019-11-30 20:27:34
Normally when ordering ascending by a field, you get the NULL values first, and then the more interesting values. Often, you want NULL values last. In MySQL, you can do this with: SELECT * FROM people ORDER BY ISNULL(name), name; However, I'm using Grails with Hibernate criteria, and I have absolutely no idea how to do this there. Is this even supported in any way? Is there some way to order by a custom SQL expression? I'd hate to rewrite all my criteria to plain SQL just to get it to sort correctly. In hibernate you can try with this below code : Criteria c = ...; c.addOrder(Order.asc("name")

Grails: Projection on many tables?

假装没事ソ 提交于 2019-11-30 20:20:24
I have some problems with projection in Grails. Could you please help me review them and suggest solutions for me? I want to query data on many tables which has many-to-one relationship and projection on some properties on both of them. For example: class Person { int id String name String address static hasMany = [cars : Car] } class Car { int id String brand long price Person owner static belongsTo = [owner : Person] } So, how can I use just one query withCriteria (apply projection) to get information of a specified car (include brand, price, and the owner name)? Is it possible to use: Car

Doctrine 2.3 Criteria. Accessing a related Object

三世轮回 提交于 2019-11-30 18:24:06
I am trying to set up a Criteria according to the Doctrine Docs . Unfortunately they don't tell you how to access attributes of an related Object. Let me give you an example. I have an ArrayCollection of Products. Every Product has a Category. I want to filter the ArrayCollection for a Category Name. Now I am trying to set up a Criteria as follows: $criteria = Criteria::create() ->where(Criteria::expr()->eq("category.name", "SomeCategoryName")); Now I get the following Exception: An exception has been thrown during the rendering of a template ("Unrecognized field: category.name") How can I

truncate/delete from given the entity class

妖精的绣舞 提交于 2019-11-30 18:16:10
I have my entity class available via a method. I'm trying to figure out, how via the JPA JPQL or Criteria API's I could issue a truncate or delete from. I think that the criteria api is more natural for working with classes, and truncate is a faster operation so these are prefered. This is what I put together so far, but not sure what to add/change about it. CriteriaBuilder cb = this._em().getCriteriaBuilder(); cb.createQuery( _entityClass() ).from( _entityClass() ); note: _entityClass returns MyEntity.class , I have no other references to MyEntity this is a more generalized implementation.