Search Results

Search found 226 results on 10 pages for 'hql'.

Page 3/10 | < Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >

  • Using NHibernate's HQL to make a query with multiple inner joins

    - by Abu Dhabi
    The problem here consists of translating a statement written in LINQ to SQL syntax into the equivalent for NHibernate. The LINQ to SQL code looks like so: var whatevervar = from threads in context.THREADs join threadposts in context.THREADPOSTs on threads.thread_id equals threadposts.thread_id join posts1 in context.POSTs on threadposts.post_id equals posts1.post_id join users in context.USERs on posts1.user_id equals users.user_id orderby posts1.post_time where threads.thread_id == int.Parse(id) select new { threads.thread_topic, posts1.post_time, users.user_display_name, users.user_signature, users.user_avatar, posts1.post_body, posts1.post_topic }; It's essentially trying to grab a list of posts within a given forum thread. The best I've been able to come up with (with the help of the helpful users of this site) for NHibernate is: var whatevervar = session.CreateQuery("select t.Thread_topic, p.Post_time, " + "u.User_display_name, u.User_signature, " + "u.User_avatar, p.Post_body, p.Post_topic " + "from THREADPOST tp " + "inner join tp.Thread_ as t " + "inner join tp.Post_ as p " + "inner join p.User_ as u " + "where tp.Thread_ = :what") .SetParameter<THREAD>("what", threadid) .SetResultTransformer(Transformers.AliasToBean(typeof(MyDTO))) .List<MyDTO>(); But that doesn't parse well, complaining that the aliases for the joined tables are null references. MyDTO is a custom type for the output: public class MyDTO { public string thread_topic { get; set; } public DateTime post_time { get; set; } public string user_display_name { get; set; } public string user_signature { get; set; } public string user_avatar { get; set; } public string post_topic { get; set; } public string post_body { get; set; } } I'm out of ideas, and while doing this by direct SQL query is possible, I'd like to do it properly, without defeating the purpose of using an ORM. Thanks in advance!

    Read the article

  • nhibernate hql date functions

    - by Russel
    Hi Im writing a notification platform using C# and NHibernate. Im having difficulties with my queries. I have a Customer entity - which contains a AssessmentCompleted Property. A notification should be sent out 21 months after certification. So my query needs to include all customers where their AssessmentCompletedDate + 21months < currentDate. How do I achieve this? Is there a month add method in nhibernate? I need to add 21 months to each AssessmentCompletedProperty...My query needs to look something like: SELECT new Notification(c.Id, c.Description, c.AssessmentCompleted + 21 FROM Cusomter c AND c.AssessmentCompleted + 21 <= :EndDate

    Read the article

  • HQL(hibernate) timestamp range match

    - by Saky
    I need to write a query to get an object between a range of time, currently the query looks like this: Timestamp from = ... Timestamp to = ... getHibernateTemplate().find("from " + Person.class.getName() + " ml where ml.lastModifiedOn>="+from.toString()+" and m1.lastModifiedOn<=" + to.toString()); However, this doesnot work for obvious reasons. How can I format the timestamp to be acceptable by the query. org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: 16 near line 1, column 123 [from Person ml where ml.lastModifiedOn=2010-02-12 16:00:21.292 and m1.lastModifiedOn

    Read the article

  • HQL Insert Query in Grails

    - by WaZ
    I want to write an insert query in Grails. I have tried all possible combinations but cant get the syntax correct. Can anybody please help? class Person { int age int name } i tried the following: Person.executeUpdate("insert into Person values (20,30)") p.s.:Please do not mention using save()

    Read the article

  • HQL make query searching by date (Java+NetBeans)

    - by Zloy Smiertniy
    Hi all I have the following issue. I have a table of reserves in my MySQL DB, the date columns is defined DATETIME. I need to make a query using hibernate to find all reserves in one day no matter the hour, just that its the same year month and date, and I'm doing this public List<Reserve> bringAllResByDate(Date date){ em = emf.createEntityManager(); Query q = em.createQuery("SELECT r FROM Reserve r WHERE r.date=:date "); q.setParameter("date", date); ... I really dont know how to make it compare, and bring me just those from the specified date, any help??

    Read the article

  • Casting to specific class in HQL

    - by bungrudi
    My situation is like this.. (note: for those who work with JBPM might already familiar with following data structures and HB mapping) Class LongInstance extends from VariableInstance, with the mapping for field "value" overridden in LongInstance. The mapping for VariableInstance is here and for LongInstance here. VariableInstance is polymorphically mapped to a collection in TokenVariableMap, the mapping is here. The question: how can I query the polymorphic collection using specific/overridden property of the member class? I'm looking for something like this "... from TokenVariableMaps tvm left join fetch tvm.variableInstances tvi where cast(tvi as LongInstance).value in(:vars)"

    Read the article

  • ADO Exception in HQL query

    - by Yoav
    I have 2 classes: Project and DataStructure. Class Project contains member List<DataStructure. My goal is to load a Project and all its DataStructures in one call. public class Project { public virtual string Id { get { } set { } } public virtual string Name { get { } set { } } public virtual ISet<DataStructure> DataStructures { get { } set { } } } public class DataStructure { public virtual string Id { get { } set { } } public virtual string Name { get { } set { } } public virtual string Description { get { } set { } } public virtual Project Project { get { } set { } } public virtual IList<DataField> Fields { get { } set { } } } Note that DataStructure also contains a list of class DataField but I don’t want to load these right now. Mapping in Fluent NHibernate: public class ProjectMap : ClassMap<Project> { public ProjectMap() { Table("PROJECTS"); Id(x => x.Pk, "PK"); Map(x => x.Id, "ID"); Map(x => x.Name, "NAME"); HasMany<DataStructure>(x => x.DataStructures).KeyColumn("FK_PROJECT"); } } public class DataStructureMap : ClassMap<DataStructure> { public DataStructureMap() { Table("DATA_STRUCTURES"); Map(x => x.Id, "ID"); Map(x => x.Name, "NAME"); Map(x => x.Description, "DESCRIPTION"); References<Project>(x => x.Project, "FK_PROJECT"); HasMany<DataField>(x => x.Fields).KeyColumn("FK_DATA_STRUCTURE"); } } This is my query: using (ISession session = SessionFactory.OpenSession()) { IQuery query = session.CreateQuery("from Project pr left join pr.DataStructure"); project = query.List<Project>(); } query.List() returns this exception: NHibernate.Exceptions.GenericADOException: Could not execute query[SQL: SQL not available] ---> System.ArgumentException: The value "System.Object[]" is not of type "Project" and cannot be used in this generic collection.

    Read the article

  • HQL: illegal attempt to dereference collection

    - by skip
    The situation is like this: I have an entity Book that holds a one-to-many relationship with Chapter. Now if I try the query, "from Book book inner join book.chapters chapter where chapter.title like '%hibernate%'", it gives me the desired result. But if I try, "from Book where book.chapters.title like '%hibernate%'", I get the error illegal attempt to dereference collection. The thing is that I only want the collection of Book objects in return and not a collection of pair of Book and Chapter objects in return which I get with the former query. Could someone help me understand?

    Read the article

  • Using NHibernate's HQL to make a query with multiple inner joins

    - by Abu Dhabi
    The problem here consists of translating a statement written in LINQ to SQL syntax into the equivalent for NHibernate. The LINQ to SQL code looks like so: var whatevervar = from threads in context.THREADs join threadposts in context.THREADPOSTs on threads.thread_id equals threadposts.thread_id join posts1 in context.POSTs on threadposts.post_id equals posts1.post_id join users in context.USERs on posts1.user_id equals users.user_id orderby posts1.post_time where threads.thread_id == int.Parse(id) select new { threads.thread_topic, posts1.post_time, users.user_display_name, users.user_signature, users.user_avatar, posts1.post_body, posts1.post_topic }; It's essentially trying to grab a list of posts within a given forum thread. The best I've been able to come up with (with the help of the helpful users of this site) for NHibernate is: var whatevervar = session.CreateQuery("select t.Thread_topic, p.Post_time, " + "u.User_display_name, u.User_signature, " + "u.User_avatar, p.Post_body, p.Post_topic " + "from THREADPOST tp " + "inner join tp.Thread_ as t " + "inner join tp.Post_ as p " + "inner join p.User_ as u " + "where tp.Thread_ = :what") .SetParameter<THREAD>("what", threadid) .SetResultTransformer(Transformers.AliasToBean(typeof(MyDTO))) .List<MyDTO>(); But that doesn't parse well, complaining that the aliases for the joined tables are null references. MyDTO is a custom type for the output: public class MyDTO { public string thread_topic { get; set; } public DateTime post_time { get; set; } public string user_display_name { get; set; } public string user_signature { get; set; } public string user_avatar { get; set; } public string post_topic { get; set; } public string post_body { get; set; } } I'm out of ideas, and while doing this by direct SQL query is possible, I'd like to do it properly, without defeating the purpose of using an ORM. Thanks in advance! EDIT: The database looks like this: http://i41.tinypic.com/5agciu.jpg (Can't post images yet.)

    Read the article

  • Hibernate HQL and Grails- How do I compare collections?

    - by BurtP
    Hi everyone (my first post!), I have an HQL question (in Groovy/Grails) I was hoping someone could help me with. I have a simple Asset object with a one-to-many Tags collection. class Asset { Set tags static hasMany = [tags:Tag] } class Tag { String name } What I'm trying to do in HQL: A user passes in some tags in params.tags (ex: groovy grails rocks) and wants to return Asset(s) that have those tags, and only those exact tags. Here's my HQL that returns Assets if one or more of the tags are present in an Assets tags: SELECT DISTINCT a FROM Asset a LEFT JOIN a.tags t WHERE t IN (:tags) assetList = Asset.executeQuery( hql, [tags:tokenizedTagListFromParams] The above code works perfect, but its really like an OR. If any of the tag(s) are found, it will return that Asset. I only want to return Assets that have those exact same tags (in number as well). Every time a new tag is created, I new Tag(name:xxx).save() so I can get the Tag instances and unique ID's for each tag that was asked for. I also tried converting the passed in tags to a list of Tag instances with Tag.findByName(t1) for each tag, and also a list of (unique) Tag Id's into the HQL above with no luck. I would appreciate any help/advice. Thank you for your time, Burt

    Read the article

  • How can I change column length using HQL query?

    - by gmugmu
    I tried session.createSQLQuery("ALTER TABLE People MODIFY address VARCHAR(1000);").executeUpdate(); but this throws org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query After a lot of googling, the recommendation is to use HQL instead of SQL query to do bulk updates. Not sure how to use HQL to accomplish this. There seems to be no decent HQL documentation for updating column length in a table. Thanks so much for the help.

    Read the article

  • Hibernate SetParameter driving me nuts.

    - by cbmeeks
    This works hql = "from State where StateCode like 'T%'"; Query query = session.createQuery(hql); This does not hql = "from State where StateCode like :StateCode"; Query query = session.createQuery(hql); query.setParameter("StateCode", "T%"); I get this 1568 [main] DEBUG org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors 1596 [main] DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker - select << begin [level=1, statement=select] 1608 [main] DEBUG org.hibernate.hql.ast.tree.FromElement - FromClause{level=1} : com.kencogroup.kkms.models.State (no alias) -> state0_ 1610 [main] DEBUG org.hibernate.hql.ast.tree.FromReferenceNode - Resolved : {synthetic-alias} -> {synthetic-alias} 1611 [main] DEBUG org.hibernate.hql.ast.tree.DotNode - getDataType() : StateCode -> org.hibernate.type.StringType@a39137 1611 [main] DEBUG org.hibernate.hql.ast.tree.FromReferenceNode - Resolved : {synthetic-alias}.StateCode -> state0_.StateCode SELECT Exception: java.lang.reflect.UndeclaredThrowableException Notice the UndeclaredThrowableException exception. What am I doing wrong? The database is SQL Server 2008 if that helps. But like I said, other queries work just fine. Thanks

    Read the article

  • How to query a date in HQL (Hibernate) with Joda Time?

    - by fabien7474
    I am sure that someone familiar with HQL (I am myself a newbie) can easily answer this question. In my Grails application, I have the following domain class. class Book { org.joda.time.DateTime releaseDate //I use the PersistentDateTime for persisting via Hibernate (that use a DATETIME type for MySQL DB) } In my HQL query, I want to retrieve books whose release date is included in range date1..date2 For instance I tried: DateTime date1, date2 ... def queryStr = "select * from Book as b where b.releaseDate > $date1 and b.releaseDate < $date2" def res = Book.executeQuery(queryStr) But I got the exception ...caused by: org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: The error token points to date format (for instance 2009-11-27T21:57:18.010+01:00 or Fri Nov 27 22:01:20 CET 2009) I have also tried to convert date1 into a Date class without success So what is the correct HQL code ? Should I convert to a specific format (which one?) using the patternForStyle method or is there another -cleaner- way to do it? Thanks, Fabien.

    Read the article

  • How to express "where value is in dynamic list" in HQL/GORM?

    - by xcut
    For a grails application, I need to find a list of objects whose "attr" is one in a dynamic list of strings. The actual HQL query is more complex, but the bit I need help with is this: def result = MyObject.executeQuery("select o from MyObject as o where o.attr in :list", [list: aListOfStrings]) This is obviously not the right syntax, Grails throws it back at me as an "unexpected token", being the :list parameter. Is this possible in HQL? I don't particularly want to use Criteria in this part of the codebase.

    Read the article

  • Is it possible to create ICriteria/ICriterion from LINQ or HQL?

    - by adrin
    I am creating a method that can create filter understood by NHibernate (by filter i mean a set of ICriteria object for example) from my abstract filter object. public static IEnumerable<ICriterion> ToNhCriteria(this MyCriteria criteria) { // T4 generated function // lots of result.Add(Expression.Or(Expression.Eq(),Expression.Eq)) expression trees - hard to generate // Is there a way to generate HQL/Linq query here istead? } then i want to do something like session.CreateCriteria<Entity>().Add(myCriteria.ToNhCriteria()) to filter entities. The problem is that using Expression. methods (Expression.Or etc) is quite tedious (the method is generated and i have multiple or statements that have to be joined into an expression somehow). Is there a way to avoid using Expression.Or() and create ICrietrion / ICriteria using LINQ or HQL?

    Read the article

  • How to I create an HQL query to return objects in a many to many relationship?

    - by Dave
    Hi there. I have an application that includes 2 classes Club and Article. These are mapped in Hibernate as a many to many relationship. As a result, hibernate has created a table called CLUB_ARTICLE which it uses to manage the many to many relation ship. The CLUB and ARTILCE tables have no direct reference to each other and the mapping is only represented in the CLUB_ARTICLE table. I need to create an HQL query that returns a list of articles for a particlular club. So I need to supply the club id and get back a list of Article objects that belong to it. For some reason, I just can't work out how to do this. Any help would be very much appriciated! Thanks.

    Read the article

  • How to dynamically order many-to-many relationship in JPA or HQl?

    - by Indrek
    I have a mapping like this: @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable( name="product_product_catalog", joinColumns={@JoinColumn(name="product_catalog", referencedColumnName="product_catalog")}, inverseJoinColumns={@JoinColumn(name="product", referencedColumnName="product")}) public List<Product> products = new ArrayList<Product>(); I can fetch the products for the catalog nicely, but I can't (dynamically) order the products. How could I order them? I probably have to write a many-to-many HQL query with the order-by clause? I though of passing the orderBy field name string to the query, or is there a better solution? Tables are: products, product_catalog, product_product_catalog (associative table) P.S. Using Play! Framework JPASupport for my entities.

    Read the article

  • How to dynamically order many-to-many relationship with JPA or HQl?

    - by Indrek
    I have a mapping like this: @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable( name="product_product_catalog", joinColumns={@JoinColumn(name="product_catalog", referencedColumnName="product_catalog")}, inverseJoinColumns={@JoinColumn(name="product", referencedColumnName="product")}) public List<Product> products = new ArrayList<Product>(); I can fetch the products for the catalog nicely, but I can't (dynamically) order the products. How could I order them? I probably have to write a many-to-many HQL query with the order-by clause? I though of passing the orderBy field name string to the query, or is there a better solution? Tables are: products, product_catalog, product_product_catalog (associative table) P.S. Using Play! Framework JPASupport for my entities.

    Read the article

  • How to deal with the Hibernate hql multi-join query result in an Object-Oriented Way?

    - by EugeneP
    How to deal with the Hibernate hql multi-join query result in an Object-Oriented Way? As I see it returns a list of Objects. yes, it is tricky and only you who write the query know what should the query return (what objects). But are there ways to simplify things, so that it returned specific objects with no need in casting Object to a specific class according to its position in the query ? Maybe Spring can simplify things here? It has the similar functionality for JDBC, but I don't see if it can help in a similar way with Hibernate.

    Read the article

  • hibernate executeUpdate IndexOutOfBounds

    - by luke
    I am trying to use an HQL to perform a simple update in hibernate, but i can't seem to get it to work. i have a query template defined as: private static final String CHANGE_DEVICE_STATUS = "UPDATE THING" +"SET ACTIVE = ? " +"WHERE ID = ?"; and then i try to execute it like this: Session s = HibernateSessionFactory.getSession(); Query query = s.createQuery(CHANGE_DEVICE_STATUS); query.setBoolean(0, is_active); query.setLong(1, id); query.executeUpdate(); But now i get this error: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.get(ArrayList.java:322) at org.hibernate.hql.ast.HqlSqlWalker.postProcessUpdate(HqlSqlWalker.java:390) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:164) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83) at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427) at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884) at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:865) at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:89) .... what am i doing wrong here? I am using hibernate 3.0 UPDATE i changed it to Query query = s.createQuery(CHANGE_DEVICE_STATUS); query.setBoolean(1, is_active); query.setLong(2, id);//<---throws here query.executeUpdate(); without changing anything else but the parameter indexes and i got this: java.lang.IllegalArgumentException: Positional parameter does not exist: 2 in query: UPDATE DEVICE_INSTANCES SET ACTIVE = ? WHERE DEVICE_INSTANCE_ID = ? at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:194) at org.hibernate.impl.AbstractQueryImpl.setLong(AbstractQueryImpl.java:244) ...

    Read the article

  • Do you test your SQL/HQL/Criteria ?

    - by 0101
    Do you test your SQL or SQL generated by your database framework? There are frameworks like DbUnit that allow you to create real in-memory database and execute real SQL. But its very hard to use(not developer-friendly so to speak), because you need to first prepare test data(and it should not be shared between tests). P.S. I don't mean mocking database or framework's database methods, but tests that make you 99% sure that your SQL is working even after some hardcore refactoring.

    Read the article

  • Why does this Grails/HQL query with a JOIN return Lists of pairs of domain classes?

    - by ?????
    I'm having trouble figuring out how to do a "join" in Groovy/Grails and the return values I get person = User.get(user.id) def latestPhotosForUser = PhotoOwner.findAll("FROM PhotoOwner AS a, PhotoStorage AS b WHERE (a.owner=:person AND a.photo = b)", [person:person], [max:3]) latestPhotosForUser isn't a list of PhotoOwners. It's a list of [PhotoOwner, PhotoStorage] pairs. Since I'm doing a PhotoOwner.findAll, I would have expected to see only PhotoOwners. Am I doing something wrong, or is this the proper behavior?

    Read the article

  • HQL multiple updates. Is there a better way?

    - by folone
    I have a Map, that I want to persist. The domain object is something like this: public class Settings { private String key; private String value; public String getKey() { ... } public String getValue() { ... } public void setKey() { ... } public void setValue() { ... } } The standard approach is to generate a Setting for each pair, and saveOrUpdate() it. But it generates way too much queries, because I need to save lots of settings at a time, and it really affects perfomance. Is there a way to do this using one update query?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >