I have the following entities defined in my Entity Model:
public class MyContainer
{
public virtual ICollection<Base> Subs { get; set; }
}
public abstract class Base
{
public virtual Guid Id { get; set; }
}
public abstract class Sub1 : Base
{
public virtual int MyValue { get; set; }
}
public abstract class Sub2 : Base
{
pub...
How can I escape the wildcard characters in a like clause?
E.g.:
select foo from Foo as foo where foo.bar like '%' || :filter ||'%'
query.setParameter("filter", "%");
query.list();
// I'd expect to get the foo's containing the '%' in bar, not all of them!
Any ideas?
...
Hi,
I'm having a problem with an HQL query
Three classes
ClassOne is my BusinessObject
public class ClassOne {
private int id;
private int status;
private Set<ClassTwo> classTwos;
+ other fields/getters/setters/constructor etc
}
ClassTwo is referenced in a set of ClassOne and is kind of the history of an object of Cl...
Hi.
For some reason I need to enter my integer values to database as string, then I want to run a query on them and compare those integers as strings. Is there any way to beautify integer numbers (between 1 and 1 US billion as an example) so I can compare them as strings?
Thanks in advance.
...
Assuming the following fictional layout
Dealership
has many Cars
has a Manufacturer
I want to write a query that says get me a Dealership with a Name of X and also get the Cars collection but use a join against the manufacturer when you do so. I think this would require usage of ICriteria. I'm thinking something like this..
...
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();
Q...
Suppose I have a map:
<map name="externalIds" table="album_external_ids">
<key column="album_id" not-null="true"/>
<map-key-many-to-many class="Major" column="major_id"/>
<element column="external_id" type="string" not-null="true"/>
</map>
How do I make a HQL meaning "select entities where map key's id...
Well, I have implemented a distinct query in hibernate. It returns me result. But, while casting the fields are getting interchanged. So, it generates casting error. What should be the solution?
As an example, I do have database, "ProjectAssignment" that has three fields, aid, pid & userName. I want all distinct userName data from this ...
Hello, I want to compare a column value to the current date, using HQL.
I tried
IQuery someQuery = session.CreateQuery(String.Format(
@"Select s.Id
From InventoryProductStateItem s
where s.ValidFrom < current_date()"));
This throws the exception "Incorrect syntax near keyword current_date()"
curre...
Hello,
I have a table which stores historical data. It's mapped to an Entity with the following fields (I use JPA with Hibernate implementation):
@Entity
@Table(name="items_historical")
public class ItemHistory{
private Integer id;
private Date date;
@Enumerated(EnumType.ORDINAL)
private StatusEnum status
@ManyTo...
Hello,
I have problems comparing the datetime property of objects and when trying to
compare to a given date. For example, I tried
IQuery query1 = session.CreateQuery(String.Format(
@"Select s.Id
From InventoryProductStateItem s
Where s.ValidFrom = " + stateItem.ValidFrom));
but get an exception...
Hey,
Say I have 3 classes
class foo1 { List<foo2> prop1;}
class foo2 { foo3 prop2;}
class foo3{ int Id;}
now I want to select distinct foo2's from foo1 and get Id of foo3.
I need to write a HQL stmt for the same.
I tried the following
select c.Id from (select distinct(a.prop1) from foo1.prop1 as a ) as b inner join b.prop2 as c...
Hi all,
I have a client application that connects to a server. The server uses hibernate for persistence and querying so it has a set of annotated hibernate objects for persistence.
The client sends HQL queries to the server and gets responses back. The client has an auto-generated set of objects that match the server hibernate objec...
I'm wondering if the following is feasible in Hibernate ; when writing an HQL query, you can say things like
select foo from Foo where foo.barString like "%baz%"
This works assuming that class Foo has a String attribute called barString.
Now, assume that Foo as a bar attribute of type Bar, but that Bar has a well-known, canonical S...
It's possible to override LAZY in HQL using LEFT JOIN FETCH.
FROM Obj AS obj LEFT JOIN FETCH obj.otherObj WHERE obj.id = :id
Is it also possible to override EAGER? How?
...
I have an class which has a collection, mapped as a bag in my nHibernate mapping file for that class, and I wish to return all instances of that class whose collection has a one or more of the objects which I pass in.
Example:
My Parent Class is called DocumentDefinition. It has a collection of Roles, which is a nHibernate entity, that...
For testing purposes, I'd like to have a console where I can just enter an HQL command and see what it returns on the grails hibernate DB (in my case a MySQL DB) while it's running e.g. in the test environment. What's the best way to do that?
I'm using Eclipse and already came across the JBoss Hibernate Tools, but I'm not sure how to co...
Is there a way to specify which index to use, in HQL, to retrieve values from a MySQL table that has an index defined?
...
I wonder if there is a way to retreive domain instances as a Map where the key is the id of the domain object.
more specific i would like to do myDomainObject.list() to return a Map instead of a List.
...
I have a table with the following structure:
ReportId Version Title .....
I want to use HQL to fetch the newest version of the report by id. Would the following query work?
from Report where reportId = :reportId and version = (select max(version) from Report where reportId = :reportId)
Is it possible to retrieve the row with the...