criteria

How to perform a join fetch in JPA Criteria without unchecked casting?

邮差的信 提交于 2021-01-28 06:30:15
问题 I need to do a JOIN FETCH in JPA Criteria using a static metamodel, however I'm at a loss on how to do it without getting an unchecked exception warning. Suppose we have a Thing entity with a lazily-initialized Other entity inside it. I want to retrieve Things with fetched Others, where other.someField="someValue". This is roughly how I would do it: public List<Thing> getThings() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Thing> cq = cb.createQuery(Thing.class); Root root =

Spring MongoDB query documents if days difference is x days

元气小坏坏 提交于 2021-01-21 06:35:49
问题 I have a collection that has two date fields and I am trying to query all records that have a difference of 15 days: { "_id" : "someid", "factoryNumber" : 123, "factoryName" : "some factory name", "visitType" : "audit", "personelId" : "somePersonel", "lastVisit": ISODate("2018-10-30T00:00:00.000+0000"), "acceptedDate" : ISODate("2018-11-16T00:00:00.000+0000") } Now in some cases acceptedDate will not be there so i need to evaluate it against the current date. Not complete sure how to write

jpa criteria compare two strings in without considering spaces

僤鯓⒐⒋嵵緔 提交于 2020-12-12 11:34:24
问题 I think that it is a basic question, but I'm struggling to get an answer. The question is: using CriteriaBuilder and Predicate how can I compare strings without considering spaces in the middle. For example: "CH 525 kV AREIA 1077 PR" . There isn't a "replace" function in CriteriaBuilder library. cb.like(equipamento.get(EquipamentoBO_.txNomeLongo), "%" + dto.getTxNomeEquipamento().toUpperCase().replace(" ", "") + "%") Thanks 回答1: There is a function method which should do the trick for you if

jpa criteria compare two strings in without considering spaces

落花浮王杯 提交于 2020-12-12 11:31:22
问题 I think that it is a basic question, but I'm struggling to get an answer. The question is: using CriteriaBuilder and Predicate how can I compare strings without considering spaces in the middle. For example: "CH 525 kV AREIA 1077 PR" . There isn't a "replace" function in CriteriaBuilder library. cb.like(equipamento.get(EquipamentoBO_.txNomeLongo), "%" + dto.getTxNomeEquipamento().toUpperCase().replace(" ", "") + "%") Thanks 回答1: There is a function method which should do the trick for you if