criteria

How do I use CriteriaBuilder to write a left outer join when relationship goes the other way?

拈花ヽ惹草 提交于 2019-12-09 03:13:58
问题 I’m using JPA 2.0, Hibernate 4.1.0.Final and MySQL 5.5.37. I have the following two entities … @Entity @Table(name = "msg") public class Message { @Id @NotNull @GeneratedValue(generator = "uuid-strategy") @Column(name = "ID") private String id; @Column(name = "MESSAGE", columnDefinition="LONGTEXT") private String message; and @Entity @Table(name = "msg_read", uniqueConstraints = { @UniqueConstraint(columnNames = { "MESSAGE_ID", "RECIPIENT" }) }) public class MessageReadDate { @Id @NotNull

Android LocationManager Criteria

不想你离开。 提交于 2019-12-09 03:10:32
问题 I need to receive location changes both from Network and GPS providers. If GPS provider not avaliable or has not location (bad sattelite visibility) I would receive location from Network provider else from GPS provider. Is it possible to select provider using criteria according to my necessity? 回答1: Actually Android Developers - Making Your App Location Aware has a great example code to meet your needs. in its code, if you use both providers (from GPS and from Network) it will do a comparison

How to set default behaviour to Grails' Criteria?

假如想象 提交于 2019-12-08 18:52:36
What I'd like to do is to set: setReadOnly(true) to every criteria query by default. Is it possible to define default settings that would be applied to every single criteria query that is executed in the application? P.S. I would possibly want to add the following as criteria defaults also but am unsure, whether they would have any additional effect to setReadOnly: setCacheMode(CacheMode.IGNORE) setFlushMode(FlushMode.MANUAL) Done some digging and found this for you: http://www.javacodegeeks.com/2012/10/stuff-i-learned-from-grails-consulting.html One limitation of the read method is that it

Hibernate: Query By Example involving one-to-many relationship

对着背影说爱祢 提交于 2019-12-08 18:27:26
I've recently started playing with the query by example component of the Criteria API and have run into a strange issue - an org.hibernate.QueryException is thrown when trying to perform a search. My scenarios is as follows: I have a class A, which as one of its properties has a set of instances of class B (Set< B> listOfBs). This is mapped as a one-to-many relationship in A. I was hoping to set a criteria query on an example instance of B, for example specifying all B's with a property value of "somevalue", and then apply that criteria to find all A's that have such a B in their set. This is

Criteria.DISTINCT_ROOT_ENTITY doesn't prevent duplicated objects

让人想犯罪 __ 提交于 2019-12-08 16:41:56
问题 I have following dao method: @Override public List<AdminRole> findAll() { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(AdminRole.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); } Actually I want to retrieve all entries from database. Sometimes I see duplicates. This happens when I add user with AdminRole. I have read that it is possible when I use EAGER fetch type and this should be fix adding

Hibernate criteria Using GROUP BY and RETURN ENTITY LIST

一个人想着一个人 提交于 2019-12-08 16:39:07
问题 I'm trying to use GROUP BY in my criteria. I need to do this: SELECT b FROM Book b GROUP BY volumeCode; I have following code: Criteria c = s.createCriteria(Book.class); c.setProjection(Projections.projectionList().add(Projections.groupProperty("volumeCode"))); List<Book> result = c.list(); But this criteria returns only volumeCode s (a list of Strings). I need to get a list of Book s. So I tried to use Transformers: Criteria c = s.createCriteria(Book.class); c.setProjection(Projections

Hibernate Criteria: distinct entities and then limit

痴心易碎 提交于 2019-12-08 15:32:21
问题 I have a criteria that returns all data the application requires, basically: Criteria criteria = session.createCriteria(Client.class); criteria.createAlias("address", "address"); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(init); criteria.setMaxResults(max); List<Client> clients = criteria.list(); The problem is that the relation client / address is bidirectional: on client has one address and one address may belong to more than one client. I want to

Hibernate Criteria Projection of non scalar values

泪湿孤枕 提交于 2019-12-08 13:35:10
问题 Is there any way to project multiple values for an root entity object using Criteria? Assume we have these classes (With the proper mappings): class Boss { private String name; private List<Employee> employees; // setters and getters and more stuff } class Employee { private String name; // setters and getters and more stuff } Then i am trying to do this : public void test() { Criteria criteria = this.getSession().createCriteria(Boss.class); criteria.createAlias("employees","employees");

Join two tables in Hibernate with Criteria API and Annotation

99封情书 提交于 2019-12-08 10:26:34
问题 I want to join 2 tables in MySQL with Hibernate Annotations and Criteria Like for example: I have 2 tables, candidates and jobs, having 2 columns each: candidates: candID & candName jobs: jobID & jobName candidates jobs candID candName jobID jobName 1 abc 1 job1 2 xyz 2 job2 i need to create a query in Criteria in hibernate as: select candName ,jobName from candidates as c ,jobs as j where c.candID = j.jobID where candName = abc and jobName=job1 what will be the criteria query for that and

NHibernate How to make Criteria inner join without hydrating objects?

拟墨画扇 提交于 2019-12-08 06:27:59
问题 Some quick nhibernate problem: I have sql tables: Item { Id, Name } ItemRange { Id, Name } ItemHasItemRange { Id, ItemId, ItemRangeId } Mappings are simple, so I will not paste them, the ItemId and ItemRangeId are foreign keys, Item class has ItemHasItemRanges collection mapped as lazy bag. I want all items which are in particular ItemRange, but I do not want to retrieve associated ItemRangeObjects, I just want to do inner join to narrow results. When I do it like that: c.CreateCriteria("Item