criteria-api

JPA 2 Criteria API: why is isNull being ignored when in conjunction with equal?

I have the following entity class (ID inherited from PersistentObjectSupport class): @Entity public class AmbulanceDeactivation extends PersistentObjectSupport implements Serializable { private static final long serialVersionUID = 1L; @Temporal(TemporalType.DATE) @NotNull private Date beginDate; @Temporal(TemporalType....

How to specify pessimistic lock with Criteria API?

I am retrieving a list of objects in hibernate using Criteria API. However I need lock on those objects as another thread executing at the same time will get the exact objects and only one of the thread will succeed in absence of a pessimistic lock. I tried like below, but it is not working. List esns=session.createCriteria(Reddy_Pool...

nhibernate multicriteria CTE subquery

I currently have a MultiCriteria query, which filters the results based on the ids being within a sub query Subqueries.PropertyIn("Id", detachedCriteria) The sub query is the same for all queries used in the multicriteria query. It seems a bit ugly looking at the sql that the sub query is repeated, in my current case 15 times. The r...

EntityManager.find can't find entity, but using the Criteria API does

I've encountered a rather odd case in Java EE 6 where using the JPA EntityManager's find method along with an entity's primary id returns null, but using the Criteria API to select all entities with that id works fine. Here is the code I'm using for find: // Always returns null, even for records I know for sure are in there. user = em....

nHibernate criteria for reversed LIKE

I have the following two entities: public class Entity1 { public IList e2 { get; set; } } public class Entity2 { public string Title { get; set; } } I only have repository for Entity1, I know I can do a LIKE query with the following criteria: criteria.CreateAlias("e2", "e1e2").Add(Restrictions.LIKE("Title", "needle", Match.Anyw...

How to specify multiple conditions on left join using JPA Criteria API?

I'd like to convert the following SQL query: select * from region_tree country left outer join region_tree region on country.REG_CODE_PAR=region.REG_CODE and region.LFT < country.LFT and region.RGT > country.RGT and region.REG_CODE_PAR = 'ALL' and COUNTRY.STATUS_CODE = 'A' and REGION.STATUS_CODE = 'A into JPA Crtieria ...

NHibernate: help translating an hql query to use criteria api instead

I have the following hql query which I'd like to switch over to the criteria API select a.Id as Id, a.Name as Name, a.ActiveStatus as ActiveStatus, dbo.GetActivityStartDate(a.Id) as StartDate, dbo.GetActivityEndDate(a.Id) as EndDate, coalesce(ac.Id,0) As CategoryId, coalesce(ac.Name,'') As CategoryName from Activity as a left oute...

Query property of enum collection mapped as element

Hi, I have the class with enum property collection: public enum PropertyType { Apartment, Townhouse, AndSoOn } public class Company { private readonly ISet<PropertyType> desiredPropertyTypes; public virtual ISet<PropertyType> DesiredPropertyTypes { get { return desiredPropertyTypes; } } // other stuff... }...

How to write DDL in the criteria API?

Consider the code in http://stackoverflow.com/questions/3333308/how-do-i-delete-all-jpa-entities The documentation here http://download.oracle.com/docs/cd/E17410_01/javaee/6/tutorial/doc/gjitv.html describes only queries. ...

Is there a tool that converts from JPQL into Criteria API?

Input: valid jpql output: java code using criteria api to achieve same jpql effects. ...

JPA 2.0 metamodel in Netbeans?

I've read that since version 6.9, Netbeans includes annotation processing support, a feature needed, for instance, to generate JPA 2.0 entities' metamodels. However, I couldn't find any examples or documentation that shows exactly how to do it. Have any of you guys succeed on this? ...

Hibernate Criteria API multiple joins

My hibernate entities are as follows: @Entity @Table(name = "EditLocks") public class EditLock extends AuditableEntity { /** The document that is checked out. */ @OneToOne @JoinColumn(name = "documentId", nullable = false) private Document document; Document then looks like this: public class Document extends Audit...

Hibernate-like Criteria API for Ruby on Rails

Is there any gem that enables you to use something like the Criteria API from the Java persistence framework Hibernate? I think Hibernate Criteria API is one of the bests APIs ever for queries and I really miss it when developing in Ruby on Rails. I really don't like the way Raills work with ActiveRecord for queries. ...

JPA Criteria API - How to add JOIN clause (as general sentence as possible)

I am trying to construct queries dynamically, and my next target is add JOIN clauses (I don't know how can I use the API). By now, for example, this code work for me : ... Class baseClass; ... CriteriaBuilder cb = JpaHandle.get().getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(this.baseClass); Root entity_ = cq.from(this.bas...

Why the compiler doesn't recognize the metamodel attributes?

Is the criteria api of eclipselink jpa2 supported for java se 6 projects? If not, that's my problem. Do I need to specify anything special to the criteria api in the persistence.xml? This is my criteria query: final EntityType<Meaning> Meaning_ = em.getMetamodel().entity(Meaning.class); final CriteriaBuilder cb = em.getCriteriaBui...

Selecting specific columns in jpa 2 Criteria API?

Is there a way to select specific column using the JPA 2 Criteria API? The following is the target SQL Statement: SELECT column1, column2 FROM MyTableThatHasMultipleColumns With Hibernate's Criteria API this can be done using Projections, is there an equivalent to the JPA 2 Criteria Specification? ...

CriteriaQuery with JPA 1.0

Hello, Is it possible to use CriteriaQuery with JPA 1.0. I guess JPA 2.0 not available with Java Se ( version -- Java(TM) SE Runtime Environment (build 1.6.0_16-b01)) . I tied to use, CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Test> cq = cb.createQuery(Test.class); Root<Test> test= cq.from(Test.class); .... But cou...

Unable to select a column from an Oracle View using JPA 2 Criteria API

I have an existing working query that selects a column from an entity mapped to an Oracle View using the following JPQL SELECT COUNT(o.id) FROM MyEntityView o I refactored it to use the JPA 2 Criteria API with the following code: MyEntityView model = new MyEntityView(); CriteriaBuilder criteriaBuilder = model.entityManage...

How to create the metamodel for multiple persistence units using the same entity classes?

I get: diagnostic error: javax.annotation.processing.FilerException: Attempt to recreate a file for type for: <compilerArguments>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml -Aeclipselink.persistenceunits=com.mysimpatico_MemoPlatform-database_nbm_1.0-SNAPSHOTPU,com.mysimpatico...

Complex querying with NHibernate

Hi, I have this problem: When I try to implement Ayende's complex searching found at: http://ayende.com/Blog/archive/2006/12/07/ComplexSearchingQueryingWithNHibernate.aspx with the object graph: Person: M:1 Address: M:1 Street: M:1 Place: ...