criteria

EclipseLink fails to fetch a scalar Boolean value

一曲冷凌霜 提交于 2019-12-11 12:19:54
问题 The following JPA criteria query succeeds on Hibernate (4.2.7 final). CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<Boolean>criteriaQuery=criteriaBuilder.createQuery(Boolean.class); Root<UserTable> root = criteriaQuery.from(entityManager.getMetamodel().entity(UserTable.class)); criteriaQuery.multiselect(root.get(UserTable_.enabled)); ParameterExpression<String>parameterExpression=criteriaBuilder.parameter(String.class); criteriaQuery.where(criteriaBuilder

cast date to ms to add long value of duration with criteria

自作多情 提交于 2019-12-11 11:38:55
问题 I have a date and duration. I need to add the duration to date. Date's format is timestamp, duration's - Long (milliseconds). How can I wright criteria to deal this issue? Practically i have something like this: 03-17-2014 21:24:57 + 2523566; 回答1: If you want to do it in Java and have a java.sql.Date and a long: public java.sql.Date dateAdd(java.sql.Date inputDate, long duration) { return new java.sql.Date(inputDate.getTime() + duration); } A java.sql.Timestamp can be used in place of a java

org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile

孤人 提交于 2019-12-11 09:32:52
问题 I have a many-to-many relationship in JPA 2.0 provided by Hibernate 4.2.0 CR1 (recently upgraded to Hibernate 4.2.7 final) between Product and Colour as follows. The Product entity class: public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "prod_id") private Long prodId; @JoinTable(name = "prod_colour", joinColumns = { @JoinColumn(name = "prod_id",

Matching *ALL* items in a list with Hibernate criteria

巧了我就是萌 提交于 2019-12-11 09:26:05
问题 So I have a Hibernate entity(lets call it Zoos) with a many-to-many relationship set up like this: @ManyToMany(cascade = {}) @JoinTable(name = "animal", joinColumns = @JoinColumn(name = "zoo_id"), inverseJoinColumns = @JoinColumn(name = "animal_id")) @LazyCollection(LazyCollectionOption.FALSE) public List<Animal> getAnimal() { return animals; } So now I want to find all zoos with the animals "lions", "tigers", and "bears". Now I don't care if they have other animals or not, but I don't want

Grails withCriteria fetch, or a fast way to sort in predetermined order

我怕爱的太早我们不能终老 提交于 2019-12-11 09:14:35
问题 A database function returns id's of all events within a certain radius, ordered by their distance. Afterwards, to preserve performance I'm eagerly loading necessary collections in withCriteria like this: def events = Event.withCriteria { 'in'('id', ids) fetchMode("someRelation", FetchMode.JOIN) // a few more joins setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) } However this messes up the ordering. I've noticed that the result of this criteria query returns all events sorted

UserType api methods are not called from Criteria Builder query in hibernate

久未见 提交于 2019-12-11 08:08:23
问题 I have a scenario where i use a custom user type for a entity field in hibernate using the org.hibernate.usertype.UserType . It's a date conversion to UTC import org.hibernate.usertype.ParameterizedType; import org.hibernate.usertype.UserType; public final class UTCTimestampType implements ParameterizedType, UserType {..} My entity class is like the below @Entity public class Person extends AbstractPerson { @Column(name = "BIRTH_DT_TM") @Type(type = "com.myexample.hibernate.types

how to write hibernate criteria query for two different tables

最后都变了- 提交于 2019-12-11 06:59:57
问题 I have these two classes @Table(name="candidateinfo") Class CandidateInfo { .... @OneToMany CandidateResume candidate; .... } @Table(name="candidateResume") Class CandidateResume { .... @ManyToOne CandidateInfo candidates; ....... } Now i want to add two restrictoins from 2 different classes(as above) in the below criteria for this i have Criteria crit = session.createCriteria(CandidateResumeInfo.class); crit.add(Restrictions.eq("resumeSearchable", 1)) ;// resumeSearchable is in

nhibernate and “NOT IN” in a aggregate subquery

99封情书 提交于 2019-12-11 06:18:13
问题 I've got an entity Reminder which contains a collection of ReminderSchedule . This is my mapping: <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Reminder" table="Reminders"> <id name="Code" type="System.Guid"> <column name="ReminderCode" /> <generator class="guid.comb" /> </id> ... <set access="field.pascalcase-underscore" cascade="all-delete-orphan" inverse="true" lazy="false" name="Schedules" mutable="true"> <key foreign-key="FK_Schedules_Reminders"> <column name=

SQL statement conversion to hibernate criteria (having count clause)

别来无恙 提交于 2019-12-11 05:59:15
问题 I have an SQL query that I would like to convert into a criteria (Hibernate 3.3.2) to use it into my persistancy layer. That's the query : select last_name from member where member.end_date > SYSDATE group by member.last_name having count(member.last_name) >1; I already try a lot a combinations, but there is no result that would be good for me ... This is my code : Criteria criteria = getSession(false).createCriteria(Member.ENTITY_NAME); criteria.setProjection(Projections.projectionList()

hibernate fetch specific column from database using criteria

左心房为你撑大大i 提交于 2019-12-11 05:49:10
问题 I want to fetch specific column from database by using criteria. select name, lastname from sssssss Please reply Thanks in advance. 回答1: you need to use the projecttion Class.. check this documentation for details.. List results = session.createCriteria(SSSS.class) .setProjection( Projections.projectionList() .add( Projections.property("name") ) .add( Projections.property("lastName") ) ) .list(); 来源: https://stackoverflow.com/questions/6715946/hibernate-fetch-specific-column-from-database