hql

How to SQL join two tables so that all entries of the left one are in the result even if there is no matching entry in the right one?

Hi everybody, I have spent several hours with this SQL problem, which I thought would be easy - I still think it should be, but obviously not easy enough for me (not an SQL expert). I would be glad if you could help me with this. I have stripped this down for this example. Imagine two tables: PRODUCT -ID -NAME REVIEW -ID -PRODUCT...

How to map a composite key with Hibernate?

In this code how to generate a Java class for composite key (how to composite key in hibernate): create table Time ( levelStation int(15) not null, src varchar(100) not null, dst varchar(100) not null, distance int(15) not null, price int(15) not null, confPathID int(15) not null, ...

How to execute BACKUP DATABASE query from grails ?

I want to backup HSQLDB from grails, Here's the command BACKUP DATABASE TO 'C:/BACKUP/' BLOCKING But how to do this in GORM where all seems Entity related even executeQuery ? Thank you for sharing your experience :) ...

Returning extra data from HQL

Hello, I'm writing an HQL query, in the form of: from a where ... or exists (from b inner join b.c where ...) and ... I get back an entity of type a from this query. However, I need to also know whether the exists clause came back true or not later on in my code. If this was SQL, I'd tack it onto the select list. However, even if I a...

How to use the entity query framework to model the following query

We have a query which needs to check if a certain integer field points is not null and if appointmentDate is before current date? How do I write the restrictions expression for the above scenario? @Entity public class User { ... Integer points; Date appointmentDate; ... } ...

Control sort order of Hibernate EnumType.STRING properties

Currently, my project uses @Enumerated(EnumType.ORDINAL), so when I sort by this column, it is ordering based on the order in the enum, which works fine. But I need to add some additional values to the enum, which need to be inserted at different locations in the list of enum values and can't be just added to the bottom to maintain the c...

Exception when using derived property in HQL

I have an entity with a derived property that maps to an entity with a composite key. Here is my mapping (using annotations) inside SampleEntity: @OneToOne(fetch = FetchType.LAZY) @JoinColumnsOrFormulas({ @JoinColumnOrFormula(formula = @JoinFormula(value = "sql comes here", referencedColumnName = "COLUMN_A")), ...

Is there a library etc that walks joins in property path expression in a Hibernate Restriction property.

It seems irritating that property paths that involve joins must be broken down into multiple criteria. This means that code building a HQL is considerably bloated especially when the path has many joins within it. I have been unable to find a library which "internally" expands paths into the right criteria. ...

How can I write an HQL to fetch this?

I have a class called Continent and Country. Continent class has Country collection: private ISet<Country> _countries; public virtual ISet<Country> Countries { get { return _countries; } set { _countries = value; } } I want to write an HQL query that will get all the continents that have countries at l...

How to query by page from to table by Hibernate?

I create 3 tables by Hibernate, how to return a List<task> when set task_status = ? and set create_user_id = ?, task_status in "dotask" table, create_user_id in task table. How to write the "HQL"? Here is mine, but I can't make it true with it: String hql="from task t left join dotask d on d.task_status = ? and t.create_user_id = ? li...

how to remove one-to-many child from parent given the child id in HQL

I've got class Parent { IList<Child> Children; } class Child { } When deleting a Child I need to remove all references to it from any Parents that reference it. How can I do this in NHibernate? There is no Parent FK on Child, the relationship is stored in a 3rd "link" table Thanks ...

Sophisticated JPQL String Query

I am trying to execute a pretty-sophisticated query on a string field in the database. I am not very experienced at JPQL, so I thought I would try to get some help. I have a field in the database called FILE_PATH. Within the FILE_PATH field, there will be values such as: 'C:\temp\files\filename.txt' 'file:\\\C:\testing\testfolder\inn...

Hibernate retrieving list from onetomany

Hi guys, I managed (as you can see in older posts from me) to insert a onetomany relation through hibernate. My two entity classes look like following: Project.java: @Entity public class Project { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @OneToMany(cascade = CascadeType.ALL, mappedBy="project") ...

"where exists" in Hibernate HQL

Hello Overflowers, How can I write a "not exists" query in HQL? I am trying to get an HQL not exists query which returns the same results as this Oracle SQL query: select * from SCHOOL a where not exists (select 1 from STUDENT b where B.SCHOOL_ID=a.id and B.STATUS_ID not in (0,1,2,3,4)) My mapping files are below: <!-- prim...

Get distinct months from database using HQL

Hi I have a java.util.Date field in an @Entity and would like to get the distinct months from that column. Suppose I only had three rows, with 14/07/2010, 24/11/1975 and 03/11/1975 (European date format - day/month/year), I would like to get the following back from Hibernate to go into a dropdown for filtering the data: 07/2010 11/197...

Regex for a simplified HQL syntax

Hi all, I intended to provide my view/business layer with the possibility to send HQL queries in strings to my data layer. However, the data layer needs to analyze and manipulate these queries (in particular, add a criterion in the where clause). The supported forms of HQL queries are any combination of the following: from ... where ...

Can I eager load a property using HQL?

I'm trying to work out how to eager load the customers in the following HQL query: select order.Customer from Order as order where order.Id in ( select itemId from BadItem as badItem where (badItemType = :itemType) and (badItem.Date >= :yesterday) ) There's the usual many-to-one relationship between orders and customers. I'd li...

Hibernate: How do I write the HQL for getting records of an entity without records for its identifying relation

I have Hibernate Objects defined as Class SomeText{ private Long textId; private Set<Tag> Tags = new HashSet<Tag>(); @ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE }) @JoinTable(name = "text_tag_reln", joinColumns = { @JoinColumn(name = "textId") }, inverseJoinColumns = { @JoinColumn(name = "tagId") }) pu...

Force Hibernate query to access database

I have loaded an entity into my transaction and have changed a property of that entity. The transaction is not yet commited. Now I would like to get the original value of the changed property. I've tried with a HQL query like select p.property from Person p where p.id = 1 with the ID of the entity loaded in the transaction. I've set q...

How do i use HibernateTemplate.findByNamedParam() ??

HI, i am trying to use the above spring hibernate temnplate method do a simple query based on a specific ID from the database but the problem is that the query doesnt replace the ":" character from the sql string below into the value contained in "id". i thought that this method replaces ":" with the given parameter i set in the method ...