hql

Format date in hql query

hi all, i want to format date to string in hql select, for example i have purchasing data with transaction date in it: class Purchase { private Date datePurchase } and i want to select date in a certain format, for example yyyyMMdd, can i do that in hql? actually i can iterate through all purchase data returned by query, and star...

findAll() Not Returning Correct Object Type

ItemTag objects contain an Item object and a Tag object. (These are Java domain objects.) This simple query works as expected. I get back a list ItemTags and can do all the wonderful things that ItemTags are supposed to do: def theTags1 = ItemTag.findAll("from ItemTag b") For example: println(theTags1[0].tag.tag) gives me this as...

Hibernate property based on sum

I have figured out that I can use hibernate to get the sum of a number of entities using HQL as follows... public Long getEnvelopeTotal(AbstractEnvelope envelope) { String query = "select sum(t.amount) from User_Transaction t"; Long result = (Long) hibernateUtil.getSession().createQuery(query).uniqueResult(); return result; ...

hql error in select clause

hello when I used sql query in hibernate (ie hql) I got following error: student is not mapped. [select stud.vStudentName from student as stud] here is table name in mysql and following is function of select query. public static void querySubject(Session session) { String sql_query="select stud.vStudentName from student as ...

HSQL Subqueries

Hi there, I have a class Order that contains a set of OrderSection's that itself contains a set of OrderItem's. In SQL, one can use a SELECT statement in a JOIN clause as done in the following query: SELECT o.id, o.amount, sum(s.quantity*s.price), sum(s.quantity*i.price) FROM orders AS o JOIN ordersections AS s...

HQL Problem

Hi every one I have these classe @Entity @Table(name = "login", uniqueConstraints={@UniqueConstraint(columnNames={"username_fk"})}) public class Login implements Serializable { @Id @Column(name = "id") @GeneratedValue private int id; @Column(name = "password", length = 64) private String password; @Column(na...

NHibernate HQL Query: Expressions in the Select clause

Is there any way to use expressions in the Select clause? E.g.: select u.Age/2 from User u I'm having this exception right now: NHibernate.QueryException: ',' expected in SELECT before:/ [select u.Age/2 from Business.Entities.User u] ...

HQL and one-to-many queries

I have Hibernate domain objects that looks like this: class Player { List<Item> inventory; } class Item { List<Enchantment> enchantments; } class Enchantment { boolean isSuperiorEnchantment; } I need to construct an HQL query that returns to me a list of all players that have at least one item wit...

How to use bitwise operators in HQL?

In HQL, how can I use bitwise operators? I want the resulting SQL query to look something like SELECT RoleId, RoleName, RolePerms WHERE (RolePerms & @Parameter) = @Parameter However, writing this HQL select from Role where (RolePerms & :param) = :param gives me this error: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of...

Converting Hibernate linq query to HQL

I understand that a IQueryable cannot be serialized. That means that queries can not be serialized, sent to a webservice, deserialized, queried and then sent back. I was wondering if it is possible to convert a hibernate linq query to hql to be sent over the wire. Is there another route I am missing? ...

Using Hibernate HQL to select records where two dates are within a specified interval

I'm trying to use HQL to find records where two date fields are within 1 month of each other. Query query = session.createQuery("from com.ep.cqprojects.db.Projects " + "where active_date - kickoff_meeting_date < interval '1' month "); Unfortunately the database used apparently doesn't understand interval. How can I compare the in...

Is it possible to bulk delete from a many-many association with HQL?

And if so, what is the syntax? Assume that I want an instance of Foo to be unassociated from all instances of Bar: In SQL it would simply be: delete from FOO_BAR_MAPPING where FOO_ID = ? In HQL, I assumed it would be something like: delete from Bar.foos foos where foos.id = :id (where foos is a mapped collection of Foo) But appea...

NHibernate How do I query against an IList<string> property?

I am trying to query against an IList<string> property on one of my domain classes using NHibernate. Here is a simple example to demonstrate: public class Demo { public Demo() { this.Tags = new List<string>(); } public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IL...

Recursive Query using HQL

Hi every one, I have this Table CREATE TABLE IF NOT EXISTS `branch` ( `id` int(11) NOT NULL AUTO_INCREMENT, `studcount` int(11) DEFAULT NULL, `username` varchar(64) NOT NULL, `branch_fk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `FKADAF25A2A445F1AF` (`branch_fk`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=14...

nhibernate hql list

Hi, I have 3 classes : public class Transformation { private int Id; private int Type; private int Ind; private IList<Action> Actions; private IList<Condition> Conditions; private Boolean IsEnabled; } public class Action { private int m_Id; private Transformation m_Tr...

How do you do a limit query in HQL

In Hibernate 3, is there a way to do the equivalent of the following MySql limit in HQL. select * from a_table order by a_table_column desc limit 0, 20; I don't want to use setMaxResults if possible. This definitely was possible in the older version of Hibernate/HQL, but seems to have disappeared. ...

MYSQL case sensitive search (using hibernate) for utf8

Hi every one, I have Login Table that have utf8 charset and utf8 collation when I want check user name and retrieve other information for this specific user name the hql query give me the same result with lowercase and uppercase. what should l do for my HQL query that work case sesitive I use Mysql 5 and java hibernarte this is my que...

How to put 'null' into column using HQL ?

How to build valid HQL string, which is equivalent to UPDATE table SET field = null WHERE .... ...

Why NHibernate simple select in HQL to SQLite database is not working ?

I've recently started using FluenNHibernate and some weird problem appeared when I tried to write unit test with SQLite. I use SQLite in memory database for test, for each test method I am clearing data existing in database. In example: var u = new User() { Name = "Piotr" }; _session.Save(u); _session.Clear(); var list = _session.Creat...

HQL left join problem: Path expected for join!

Hi, I am new at Hibernate, and I have a question regarding HQL Lejt join. I try to left join 2 tables, patient and provider, and keep getting "Path expected for join! " erroron the second table. Appreciate it if anybody can help on this issue! Here is the mapping of the 2 tables/classes: patient.hbm.xmL: <?xml version="1.0"?> <!DOC...