criteria-api

Jpa Criteria API count

最后都变了- 提交于 2019-12-12 09:53:10
问题 I've been trying to get total rows count and to do so, I've used JPA Criteria API but it throws an error at Long count = em.createQuery(sc).getSingleResult(); line and saying java.lang.IllegalStateException: No criteria query roots were specified . I've done some research but couldn't narrow the problem. Here's my code snippet; @PersistenceContext public EntityManager em; ...... public Page<UserDTO> findByCriteria(String filters, Pageable pageable) { CriteriaBuilder cb = em.getCriteriaBuilder

How to refer to a subclass specific field in a CriteriaQuery where the super class is queried?

半腔热情 提交于 2019-12-12 07:12:52
问题 I'm trying to achieve something like the following, using the JPA Criteria API: SELECT b FROM Box b JOIN SpecialItem s WHERE s.specialAttr = :specialAttr The objects are Box @Entity public class Box implements Serializable { ... @ManyToOne @JoinColumn( name = "item_id" ) Item item; ... } Item @Entity @Inheritance( strategy = InheritanceType.JOINED ) public class Item implements Serializable { @Id private String id; ... } SpecialItem @Entity public class SpecialItem extends Item { private

JPA Criteria API calling SQL Server database exist function

巧了我就是萌 提交于 2019-12-12 04:12:48
问题 I am building a query using the JPA's CriteriaBuilder to call the SQL Server exist function to find data based on an XML field and it is failing to run due to a The argument 1 of the XML data type method "exist" must be a string literal. error. I traced the SQL generated and get the same error when I try the query in SQL Server Management Studio. I've simplified the SQL to the following for reference declare @p1 int set @p1=NULL exec sp_prepexec @p1 output, N'@P0 varchar(8000)', N'select id,

JPA - Query with 'composite values' in where-clause

戏子无情 提交于 2019-12-12 02:43:33
问题 I want to realize the following (for this example: MySQL) statement in JPA 2.1 with Eclipselink as the implementation: select * from account where (mailing_zip_code, id) > (56237, 275) order by mailing_zip_code asc, id asc limit 10; What I want to achieve is an implementation of the seek method for endless scrolling without using an offset in the query. With focus on the where clause, I am not able to find a correct name for this construct. In some places it is called 'composite value', but I

Criteria api equivalent for joining child with parent

青春壹個敷衍的年華 提交于 2019-12-12 02:26:00
问题 Version: Hibernate 3.3 Hi, I have 2 simple models: class Parent { Long id; //auto generated sequence and primary key String name; Set<Child> children; } class Child { Long id; String name; Parent parent; } with the following hbm: <class name="my.Parent" table=PARENT"> <id name="id" column="PARENT_ID" type="java.lang.Long"> <property name="name" column="NAME" type="java.lang.String"> <set name="children" table="CHILDREN" inverse="true"> <key><column name="PARENT_ID" not-null="true" /></key>

How to make a like query to @ElementCollection of type map?

一世执手 提交于 2019-12-12 02:12:23
问题 I have a class like this: class MyEntity { @ElementCollection Map<String, String> properties; } I'd like to find out which MyEntity entities have a property value that matches like query using the criteria API. By this I mean I'd like to make a like query on the values of the map entries. For example if one of my MyEntity classes has a property named "email" and the value is "example@mail.com", how do I make a query that finds the entity with a query parameter "example%" using criteria API?

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);

criteria query: indistinct result lists

你说的曾经没有我的故事 提交于 2019-12-11 22:55:58
问题 I have 2 little problems. Let's say I have an entity class called MyEntity . This class has two kinds of properties. Therefore I have two different class Property1 and Property2 which are also entity classes. There are bidirectional relations betweens MyEntity and the property classes, especially Property1 has an attribute List<MyEntity> owningEntities and Property2 has the attribute MyEntity owningEntity . Now I have the following query: SELECT e FROM Property1 p JOIN p.owningEntities e

Hibernate criteria implementation for this entity model (subquery, self-join)

穿精又带淫゛_ 提交于 2019-12-11 21:08:12
问题 Given the following entity one-to-many model: One Repository can be linked to many AuditRecords. Many AuditRecords can all link to the same Repository @Entity class AuditRecordEntity { private AuditRepositoryEntity auditRepository; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = AUDIT_REPOSITORY_DB_COLUMN_NAME, nullable = false, updatable = false) public AuditRepositoryEntity getAuditRepository() { return auditRepository; } ... } @Entity class AuditRepositoryEntity { private List

Criteria Builder with predicate

亡梦爱人 提交于 2019-12-11 18:46:12
问题 I have list of object which I will read from property file and then I will split with pipe symbol and then I need to apply with or clause. Below is the code. When I try to apply builder.or the below query is getting genareted, instead of or clause. String coverageNames = env.getRequiredProperty(AmhiConstants.COVERAGE_NAME); String[] coverageName = coverageNames.split(Pattern.quote("|")); CriteriaBuilder builder = manager.getCriteriaBuilder(); TypedQuery typedQuery; CriteriaQuery<Integer>