criteriaquery

Polymorphic CriteriaQuery without inverse relationship

↘锁芯ラ 提交于 2019-12-20 17:42:22
问题 I have the following EJB structure. Don't wonder about Animal and Inventory , these classes are only here to demonstrate the structure in a simplified way ( Update : I have revised the class names to construct a better understandable example. Another implementation of IdTag might be a BarcodeId ). Note that there is no inverse relationship from IdTag to Animal or Inventory , and let's assume the RfidTag.code is unique. I read Retrieving Polymorphic Hibernate Objects Using a Criteria Query and

JPA Query selecting only specific columns without using Criteria Query?

和自甴很熟 提交于 2019-12-17 03:35:14
问题 Is it possible to select, say, only properties A and B from an object using a JPA query without using criteria queries? To select all properties I'd just do something like: SELECT i FROM ObjectName i WHERE i.id = 10 But I have an object with many properties on a legacy system, and want to select just a few even though I'm aware selecting several properties is usually quick. Is this possible without using criteria queries? Thank you! 回答1: Yes, like in plain sql you could specify what kind of

Exception in getting list from CriteriaQuery

筅森魡賤 提交于 2019-12-11 23:05:10
问题 for some reason i can't tell, there is exception when i try to get a list from CriteriaQuery using subquery. some one please help!!! here is the code: public String[] getProductsDistinctBySubQueriesName(String category) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); //subquery Subquery<Integer> subqueries = criteria.subquery(Integer.class); Root<Productscategory> productCategory = subqueries.from(Productscategory.class);

How to join multiple columns using Specification in JPA?

左心房为你撑大大i 提交于 2019-12-11 16:24:29
问题 I'm trying to convert a query into a JPA Specification, the query contains JOIN operation with OR condition. Here is the Query : select u from User u inner join Operation o on (u.id = o.verificateur1 or u.id = o.verificateur2) where o.id not in (:ids) I tried to write a specification but I'm blocked on how to join multiple column with OR condition. public class UserSpecification { public static Specification<User> UsersNotInSelectedOperations(final List<Long> operationId ){ return new

Complex criteria query: using JPA instead of NativeQuery

[亡魂溺海] 提交于 2019-12-11 02:53:59
问题 I've in my Java EE project this NativeQuery for MySQL: SELECT *, ROUND((price_2-price_1)*100/price_1,2) AS varprice_1, ROUND((quantity_2-quantity_1)*100/quantity_1,2) AS varcant_1, ROUND((price_3-price_2)*100/price_2,2) AS varprice_2, ROUND((quantity_3-quantity_2)*100/quantity_2,2) AS varcant_2, 1 FROM ( SELECT c.id_customer AS id_customer, c.name AS customer, r.id_rep AS id_rep, r.descr AS rep, a.id_article AS id_article, a.name AS article, ROUND(SUM(if(docdate BETWEEN '2013-06-30' AND '2013

jpa2 CriteriaBuilder order by “ORDER BY expressions must appear in select list”

心已入冬 提交于 2019-12-10 21:08:19
问题 I'm writing a query with CriteriaBuilder , but it has not been possible to add the order by clause, because an error it's thrown with the message ORDER BY expressions must appear in select list this are my entities. public class A{ Integer aId; @ManyToOne @JoinColumn(name = "bId", nullable = false) B classB; //setter and getter. } public class B{ Integer bId; String name; //setter and getter. } my query look like this. CriteriaBuilder cb = super.getEntityManager().getCriteriaBuilder();

How to rewrite this query using JPA Criteria Query?

戏子无情 提交于 2019-12-08 00:57:40
问题 public class Entity { private boolean suspended; private String code; @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime") @DateTimeFormat(style = "S-") private DateTime validFrom; @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime") @DateTimeFormat(style = "S-") private DateTime validTill; } Meaning of query: "Is the code unique in given time validity?" How to rewrite this query: select count(o) from Entity o where o <> :this and o.code = :code and ( (o

Is there a way to reduce the amount of boiler-plate code associated with a CriteriaQuery (in JPA 2.0)?

泪湿孤枕 提交于 2019-12-07 02:27:08
问题 I love the type safety CriteriaQuery brings ing JPA 2.0 but it also brings a bit of boiler-plate code. For example, let say I have an entity called NamedEntity, which simply has an id and a String field called "name" (assume it has the unique constraint set to true). Here's what the NamedEntityManager might look like: public class NamedEntityManager { //inject using your framework EntityManager entityManager; //retrieve all existing entities of type NamedEntity from DB public Iterable

How to get an interesect query using CritieraQuery?

纵饮孤独 提交于 2019-12-06 12:47:39
问题 Given @Entity public class Document { @Id @Column(name = "DOCUMENT_ID") private Long id; @ElementCollection @CollectionTable( name="TAG", joinColumns=@JoinColumn(name="DOCUMENT_ID") ) @Column(name="TAG") private Set<String> tags; } find all documents tagged with a specific collection of tags. Essentially, an EclipseLink equivalent of: SELECT d FROM Document d WHERE :tag1 MEMBER OF d.tags INTERSECT SELECT d FROM Document d WHERE :tag2 MEMBER OF d.tags ... SELECT d FROM Document d WHERE :tagn

Condition left join in CriteriaQuery

无人久伴 提交于 2019-12-05 09:30:51
Hi everybody I am trying to do this in CriteriaQuery, I was searching so long but I can't found anything to do it, someone can help me? SELECT b.name FROM Empl a LEFT OUTER JOIN Deplo b ON (a.id_depl = b.id_depl) AND b.id_place = 2; I'm just trying to do a condition in left join clause, I saw ".on" function but I don't know if it will work and how it work because I tried to do something like this: Join Table1, Table2j1 = root.join(Table1_.table2, JoinType.LEFT).on(cb.and(cb.equal(table2_.someid, someId))); But it need a boolean expresion. The on clause has been introduced in JPA 2.1. An