criteria-api

JPA Criteria Query - How to implement Join on two tables to get desired result in single Query

南楼画角 提交于 2019-12-01 13:54:24
I have 2 classes mapped with db Tables. Composite Primary Key Class : @Embeddable public class Pk implements Serializable, Cloneable { @Column(name = "dataId") private String dataId; @Column(name = "occurrenceTime") private Timestamp occurrenceTime; public String getDataId() { return dataId; } public Pk setDataId(String dataId) { this.dataId = dataId; return this; } public Timestamp getOccurrenceTime() { return occurrenceTime; } public Pk setOccurrenceTime(Timestamp occurrenceTime) { this.occurrenceTime = occurrenceTime; return this; } @Override public boolean equals(Object o) { if (this == o)

Criteria/aggregation: search for all complete documents whose array field has element with latest given status

老子叫甜甜 提交于 2019-12-01 12:47:04
I have document structure like this - { "_id" : "11223344", "orderId" : "00001041", "key" : "56h68ab4c876dbe1cd0b1ee" "status" : [ { "updatedTimeStamp" : ISODate("2017-06-01T16:05:42.737Z"), "orderStatus" : "INITIATED" }, { "updatedTimeStamp" : ISODate("2017-06-01T16:05:42.737Z"), "orderStatus" : "CONFIRM_PAYMENT" }, { "updatedTimeStamp" : ISODate("2017-06-01T16:07:36.797Z"), "orderStatus" : "RESTAURENT_CONFIRMATION_PENDING" }, { "updatedTimeStamp" : ISODate("2017-06-01T16:20:36.798Z"), "orderStatus" : "ORDER_CONFIRMED" }, { "updatedTimeStamp" : ISODate("2017-06-01T16:51:27.562Z"),

How to populate DTO class string fields using JPA CriteriaQuery on Entity having enum fields?

断了今生、忘了曾经 提交于 2019-12-01 08:22:55
问题 I'm using JPA Criteria API, and in my query multiselect I want to retrieve an enum attribute, and not the enum itself. This is my query : final CriteriaQuery<MyClassDTO> query = builder.createQuery(MyClassDTO.class); in MyClassDTO I have 4 fields as following: private String icon; private String provenance; private int sizeX; private int sizeY; And the path I'm retrieving data from is : final Root<MyClass> from = query.from(MyClass.class); MyClass has 3 fields : @Column @Enumerated(EnumType

Eclipselink extend JOIN clause

时间秒杀一切 提交于 2019-12-01 06:45:35
The current code: CriteriaQuery criteriaQuery = cb.createQuery(MinutisPreke.class); Root<MinutisPreke> from = criteriaQuery.from(MinutisPreke.class); Join<LankomumasDiena, MinutisPreke> ld = from.join("lankomumasDiena", JoinType.LEFT); cb.and(cb.equal(ld.get("intervalas"), 7)); generates the following query: SELECT COUNT(t0.pr_id) FROM preke AS t0 LEFT OUTER JOIN lankomumas AS t1 ON (t1.pr_id = t0.pr_id) WHERE (t1.intervalas = 7) How to add statement in the LEFT OUTER JOIN ON clause using criteria query so my code would generate this query: SELECT COUNT(t0.pr_id) FROM preke AS t0 LEFT OUTER

JPA: How to perform a LIKE with a NUMBER column in a static JPA MetaModel?

依然范特西╮ 提交于 2019-12-01 06:08:20
问题 I do have a static metamodel with a NUMBER (actually, BigDecimal, don't ask why) column. Now I would like to do a LIKE query against that number column: CriteriaBuilder cb; cb.like(entity.get(Entity_.numbercol), "123%"); where entity.get(Entity_.numbercol) returns a Path<BigDecimal> . Naturally, I get a compile error: ...like(Expression<String>, ...) ... not applicable for the arguments (Path<BigDecimal>, ...) Casting the column with .as(String.class) fails due to some Bug in JPA, but I don't

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 -

Why the compiler doesn't recognize the metamodel attributes?

别说谁变了你拦得住时间么 提交于 2019-12-01 05:17:24
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.getCriteriaBuilder(); CriteriaQuery<Integer> cq = cb.createQuery(Integer.class); final Root<Meaning> meng = cq.from(Meaning.class); cq.where(meng.get(Meaning_.lastPublishedDate)); //this attributes are not recognized/found cq.select(meng.get(Meaning_.objId)); // " " TypedQuery

How to query for entities by their collection value

核能气质少年 提交于 2019-12-01 04:40:24
I'm using jpa and I have the following entity: @Entity @Table(name="favorites_folders") public class FavoritesFolder { private static final long serialVersionUID = 1L; @Id private String id; @NotNull @Size(min = 1, max = 50) public String name; @ElementCollection(fetch = FetchType.LAZY) @CollectionTable( name="favorites_products", joinColumns=@JoinColumn(name="folder_id") ) @Column(name="product_id") @NotNull private Set<String> productsIds = new HashSet<String>(); } What I want to do is to get a set of FavoritesFolder entities that contains the string "favorite-id" in their productsIds member

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

Why the compiler doesn't recognize the metamodel attributes?

左心房为你撑大大i 提交于 2019-12-01 02:09:27
问题 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.getCriteriaBuilder(); CriteriaQuery<Integer> cq = cb.createQuery(Integer.class); final Root<Meaning> meng = cq.from(Meaning.class); cq.where(meng.get(Meaning_.lastPublishedDate));