What is the recommended way to truncate a table using hibernate/hql?
I've tried this:
Query query = session.createQuery("truncate table MyTable");
query.executeUpdate();
But it didn't work (truncate doesn't seem do be documented anywhere in hql...)
...
Assuming two tables, A[a_id, b_id] and B[b_id,c].
I need to execute the HQL query of form "From A a ORDER BY a.b.c", while b is nullable in class A.
The query,however, returns only instances of A which have non-null b property.
This happens because Hibernate generates SQL of form "SELECT FROM A,B WHERE A.b_id = B.b_id ORDER BY B.c"
Wh...
hello, i try to make a gui for some queries i work with netbeans and mysql and i have for example a student table with 6 fields age,id,year,...
when i type the query:
from Students
it shows all the fields of the table and all data perfectly
when i type a query like
select year from Students
I got a table but not with the year field ...
Hi
I'm trying to write an NHibernate HQL query that makes use of parenthesis in the where clause. However, the HQL parser seems to be ignoring my parenthesis, thus changing the meaning of my statement. Can anyone shed any light on the matter?
The following HQL query:
from WebUser u left join fetch u.WebUserProfile left join fetch...
I'm fairly new to HQL / NHibernate so this may be a bit of an amateurish question. Basically I have a bidirectional many-to-one association. In my query, I am trying to find all of the “parent” entities that contain “children” that match a certain criteria.
I really don’t want to run the first query on the children and then query the p...
Why does this query NOT work
FROM WorkflowConfiguration
WHERE ((saReplacement IS NOT NULL) AND (:currentTime >= saReplacement.start) AND (saReplacement.end >= :currentTime)) OR
((hrmsAdminReplacement IS NOT NULL) AND (:currentTime >= hrmsAdminReplacement.start) AND (hrmsAdminReplacement.end >= :currentTime)) OR
...
Trying to go from here this SQL:
SELECT DISTINCT iss.ID
FROM Issue AS iss
INNER JOIN Message ON Message.IssueID = iss.ID
INNER JOIN Clinician ON Clinician.UserID = Message.FromUserID
INNER JOIN OrgUnit ON OrgUnit.ID = Clinician.OrgUnitID
WHERE OrgUnit.ID = [id-number]
To here in HQL:
select distinc...
I have
Entity A
- type
- uniqueKey
and
Entity B
- uniqueKey
and i dont know how to integrate it into hibernate that i can produce results like from this query:
select * from A
left join B on B.uniqueKey = A.uniqueKey and A.tpye = 1
where
A.id is null
this will produce a result that has all the entries of B that are not in A fo...
Dear ladies and sirs.
Does anyone know of an existing solution to translate a LINQ Expression to HQL statement?
Thanks in advance to all the good samaritans out there.
P.S.
We already use Linq to NHibernate. However, it only works for select statements, whereas HQL is good for other statement kinds, like delete. So, Linq to NHibernat...
I'm trying to write a query in HQL, and I'm having some trouble with it. It's probably not too difficult, but I'm pretty awful at query languages in general and HQL in specific.
Basically, there are three tables, Owners, Pets, and Toys, whose classes look like this:
public class Owner {
long ownerId;
List<Pet> pets;
}
public class P...
I have the following HQL query that is attempting to return 2 object instances as well as an aggregate count based upon a 3rd object instance.
SELECT
client,
clientCampaign,
count( formData )
FROM
FormData as formData
JOIN formData.deliveryResults as deliveryResults
JOIN formData.leadForm as leadForm
JOIN leadForm.campaignForms a...
the field definition
/** Date. */
@Column(columnDefinition = "datetime")
private Date date;
setter
public void setDate(final Date date) {
DateFormat dfmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
this.date = dfmt.parse(dfmt.format(date));
} catch (ParseException e) {
// TODO Auto-generated catc...
I have a persistent class Author with two fields: int id, String name.
Problem is that whenever I execute query this way:
Session s = HibernateUtil.getSessionFactory().getCurrentSession();
s.beginTransaction();
Query q = s.createQuery("from Author");
return (Author)q.list().get(0);
It works fine and returns me an Author object with ...
Hi,
I am working query with little idea of what software I am dealing with and minimum knowledge HQL.
What I am looking is,
SELECT Entity1 FROM Entity AS Entity1
WHERE (EXISTS ELEMENTS(Entity1.config.dateTimeInfo.ntpConfig.server) )
But I want to set a condition saying
WHERE count(ELEMENTS(Entity1.config.dateTimeInfo.ntpConfig.se...
Hi,
I need help with an nhibernate query. I would prefer to use Criteria API if possible, otherwise HQL is ok.
I have an Employee object with an Account object property, the Account has a collection of Entry objects, and each Entry has an Amount property. (see class diagram).
http://www.threeboxes.com.au/employeeQuery1.jpg
I need a q...
Trying to do a bit more complex query, and thought that HQL would be better for the job. Using nHibernate.
SELECT * FROM [Group] g
INNER JOIN [User2Group] ug on g.Id = ug.GroupId
INNER JOIN [User] u ON u.Id = ug.UserId
INNER JOIN Activity a on g.ActivityId = a.Id
WHERE u.Id = ? AND a.Lineage LIKE '?%'
I guess I could also just...
SELECT *
FROM [Group] g
INNER JOIN User2Group ug
**on g.Id != ug.GroupId**
INNER JOIN [Activity] a
on a.Id = g.ActivityId
WHERE g.UserId != 2
AND a.Lineage like '0,1,%'
Group > 1-n > User2Group < n-1 < User
m-n relationship
Activity > 1-n > Group
1-n
Trying to get all groups that a user has not already added to their account....
consider table
sales (id, seller_id, amount, date)
and here is a view that is generated from sales using query SELECT seller_id, SUM(amount) FROM sales GROUP BY seller_id
total_sales (seller_id, amount)
I want to make an entity for total sales but without the view on the sql side.
This entity will be constructed from a query. The ...
Hi,
I have the following Grails domain objects
class ProductType {
String name
static hasMany = [attributes: Attribute]
}
class Attribute {
Boolean mandatory = false
Integer seq
static belongsTo = [productType: ProductType]
}
I would like to get all ProductTypes and their mandatory Attributes. Furthermore, I'd ...
Hello Hibernate Experts,
i would very much appreciate your help in transforming the following SQL statement to a valid HQL Statement. I tried for hours but was not successfull:
SELECT * FROM master as m left outer join (select * from child as c where c.id = (select max(d.id) from child as d where d.MasterFk = c.MasterFk) )as b ON m.id...