criteria

hibernate query language or using criteria?

徘徊边缘 提交于 2019-12-01 08:22:46
问题 Any one who tell me the query using criteria/hql/sql. Requirement is that user enter email or username the query return the password of the user from table user. 回答1: If all you're doing is fetching one field, you probably just want to go hql (or possibly sql). If you do criteria, I believe you're pulling back the entire object, just to eventually use one field. Edit: That's a really broad question. Here is a tutorial 回答2: The Criteria API is very appropriate for dynamic query generation and

NHibernate: can't successfully set lazy loading

守給你的承諾、 提交于 2019-12-01 08:04:45
问题 I have a table Parent and a table Child. Child contains a foreign-key to the Parent table, creating a one-to-many relationship. Here is a part of my mapping that I define with fluent NHibernate: public class ParentMap : ClassMap<Parent> { public ParentMap() { WithTable("Parents"); Id(x => x.Id, "ParentID") .WithUnsavedValue(0) .GeneratedBy.Identity(); Map(x => x.Description, "Description"); HasMany<Child>(x => x.Childs) .LazyLoad() .WithKeyColumn("ParentID") .IsInverse() .AsSet(); } } public

Hibernate: getting too many rows

久未见 提交于 2019-12-01 06:36:17
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.persistence.Entity @Table(name = "my_table") public class My extends MyEntity<MyPK> { @EmbeddedId private

How to use MySQL functions in Propel

限于喜欢 提交于 2019-12-01 05:56:37
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) string and I get no records. What I've done for now is: $c->add(FoobarPeer::CREATED_AT, "created_at >

NHibernate Criteria Where any element of list property is true

喜欢而已 提交于 2019-12-01 05:40:26
问题 I have an already created NHibernate Criteria query that I need to modified so I can add a new condition. The query is based on the Order object, which has a list of OrderItems and then, every OrderItem has a bool property named FinalDeliveryIndicator . In my Criteria query I need to add a condition in which I want all orders that at least one of its OrderItems has the FinalDeliveryIndicator bool set to true . The query, at the moment, is: var search = NHibernateSession.CreateCriteria(typeof

JPA criteria query in a many-to-many relationship

孤人 提交于 2019-12-01 05:33:35
I'm using JPA 2.0 in EclipseLink 2.3.2 in which I have a many-to-many relationship between products and their colours. A product can have many colours and a colour can be associated with many products. This relationship is expressed in the database by three tables. product prod_colour (join table) colour The prod_colour table has two reference columns prod_id and colour_id from its related parent tables product and colour respectively. As obvious, the entity class Product has a set of colours - java.util.Set<Colour> which is named colourSet . The entity class Colour has a set of products -

Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria

纵然是瞬间 提交于 2019-12-01 05:24:38
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"); criteria.add(Expression.eq("lang.langCode", "EN")); subCriteria.add(Restrictions.eqProperty("model

Hibernate Criteria: Left Outer Join with restrictions on both tables

陌路散爱 提交于 2019-12-01 03:59:16
I am doing a LEFT OUTER JOIN, but I am only able to apply Restrictions on the first table. Is there a way ti apply on the second table as well? Here is my code: Criteria criteria = this.crudService .initializeCriteria(Applicant.class).setFetchMode("products", FetchMode.JOIN);. This works (applicant has an applicantName property): criteria.add(Restrictions.eq("applicantName", "Markos") Neither of these works (product has a productName property) criteria.add(Restrictions.eq("productName", "product1") criteria.add(Restrictions.eq("products.productName", "product1") // products: the name of the

JPA criteria query in a many-to-many relationship

倾然丶 夕夏残阳落幕 提交于 2019-12-01 03:57:09
问题 I'm using JPA 2.0 in EclipseLink 2.3.2 in which I have a many-to-many relationship between products and their colours. A product can have many colours and a colour can be associated with many products. This relationship is expressed in the database by three tables. product prod_colour (join table) colour The prod_colour table has two reference columns prod_id and colour_id from its related parent tables product and colour respectively. As obvious, the entity class Product has a set of colours

JPA Criteria API: query property of subclass

荒凉一梦 提交于 2019-12-01 03:45:02
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 = builder.createQuery(CartItem.class); Root<CartItem> root = query.from(CartItem.class); builder.equal(root