hql

NHibernate HQL's Equivalent to T-SQL's TOP Keyword

ぃ、小莉子 提交于 2019-12-04 15:34:15
问题 What is NHibernate HQL's Equivalent to T-SQL's TOP Keyword? Also what is the non-HQL way for saying give me the first 15 of a class? 回答1: It's actually pretty easy in HQL: var top15 = session.CreateQuery("from SomeEntity") .SetFirstResult(0) .SetMaxResults(15) .List<SomeEntity>(); Don't know how to do this using the criteria API though. 回答2: Criteria API Method: ICriteria criteria = DaoSession.CreateCriteria(typeof(T)); criteria.SetFirstResult(StartIndex); criteria.SetMaxResults

Join Non ContentPart Table to ContentPart Table Using Orchard HQL API

独自空忆成欢 提交于 2019-12-04 14:58:34
I am trying to perform a simple join between two different tables using the Orchard HQL API. The problem is that one of the tables is not a ContentPartTable. Is this possible?? Here is what it would look like in regular SQL: Select * From ItemPartRecord Join ItemRecord On ItemRecord.ItemId = ItemPartRecord.ItemId Where ItemRecord.Price Between 1000 and 10000 How exactly could I go about doing this? If anyone is wondering how to do this: //Join the non content part table var defaultHqlQuery = query as DefaultHqlQuery; var fiJoins = typeof(DefaultHqlQuery).GetField("_joins", BindingFlags

Nhibernate: distinct results in second level Collection

只愿长相守 提交于 2019-12-04 14:54:30
I have an object model like this: class EntityA { ... IList<EntityB> BList; ... } class EntityB { ... IList<EntityC> CList; } I have to fetch all the colelctions (Blist in EntityA and CList in EntityB), because if they all will be needed to make some operations, if i don't eager load them i will have the select n+1 problem. So the query was this: select a from EntityA a left join fetch a.BList b left join fetch b.CList c The fist problem i faced with this query, was the return of duplicates from the DB, i had EntityA duplicates, because of the left join fetch with BList. A quick read through

Spring security/hibernate: Bad credentials even if they're right?

丶灬走出姿态 提交于 2019-12-04 14:44:33
Hey I am having a bit of a mess with my springsecurity based login I'm keep getting the error "bad credentials" Here's my user table: ![Usertable][1] Here's my dataSource from the applicationContext: <!-- database driver/location --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/ams" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> and my securityContext: <?xml version="1.0" encoding=

dynamically Search Query in HQL with optional Parameter?

自古美人都是妖i 提交于 2019-12-04 14:02:02
i am developing an application in which i need search functionality, i want to write HQL query that dynamically create according to parameters. Currently i have 4 parameters, while searching all parameters are required or 1 or 2 or 3 parameters required according to how user want to searchs. public List<Plot> fetchSearchedPlots(int plotType, String plotSize, String min, String max) { Session session = sessionFactory.getCurrentSession(); List<Plot> searchedLists = new ArrayList<Plot>(); String query = "FROM Plot where type = ? and size = ? and price >= ? and price <= ?"; searchedLists = (List

Converting SQL to HQL [closed]

折月煮酒 提交于 2019-12-04 13:53:27
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 11 years ago . I'm trying to convert the below SQL query to HQL and am having a few issues. A straight line by line conversion doesn't work, I am wondering if I should be using an Inner Join in the HQL? SELECT (UNIX_TIMESTAMP(cosc1.change_date) - UNIX_TIMESTAMP(cosc2.change_date)) FROM customer_order_state_change cosc1 LEFT JOIN customer_order_state cos1_new on cosc1.new_state_id = cos1_new.customer_order_state_id

Hibernate Session closed problem!

隐身守侯 提交于 2019-12-04 13:20:27
问题 The function below is the actionListener for a button I have in my web application, I am deleting the old chosen rows from a table in a database and inserting the new ones to the database. public void getSelectedExemptionItems(ActionEvent ae) { Session hibernateSession; Session hibernate2Session; selectedExemptions = new ArrayList<ExemptionBean>(); for (ExemptionBean eBean : exemBean) { // iterating over the list of ExemptionBean class if (selectedExemptionIDs.get(eBean.getExemptionID())

Hibernate throws NullPointerException from HqlSqlWalker

£可爱£侵袭症+ 提交于 2019-12-04 13:11:38
I have a web application, which has a search form and HQL is generated on the fly. Also, user can click on the column headers to sort items as needed. Some columns get ther data from very deep down the structure. I have this HQL, for example, which works flawlessly: SELECT s FROM Application s LEFT JOIN s.product AS product LEFT JOIN product.originCountry AS origin WHERE s.nr = ? ORDER BY origin.name ASC But this one fails miserably: SELECT s FROM Application s LEFT JOIN s.product AS product LEFT JOIN product.producer AS producer LEFT JOIN producer.address AS address LEFT JOIN address.country

Parameterizing a HQL IN clause using HqlBasedQuery?

别说谁变了你拦得住时间么 提交于 2019-12-04 12:23:43
问题 How do you pass a list of things for the 'in' clause in Nhibernate HQL? e.g. // data input from the user interface, not known at compile time object[] productIds = {1, 17, 36, ... }; string hqlQuery = @" from Product as prod where prod.Id in ( ? )"; HqlBasedQuery query = new HqlBasedQuery(typeof(Product), hqlQuery, productIds) ActiveRecordMediator.ExecuteQuery(query); Now, this isn't going to work, as much as I wish it would! Am I really stuck doing something like this: // data input from the

Why does this HQL delete fail, when an HQL select with same terms works?

狂风中的少年 提交于 2019-12-04 12:08:06
Why does the following HQL query fail? string hql = @"delete MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; session.CreateQuery(hql) .SetDateTime("threshold", threshold) .SetEnum("application", this.application) .ExecuteUpdate(); The same form of query works when used in a select: string hql = @"from MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; IList<MyLog> log = session.CreateQuery(hql) .SetDateTime("threshold", threshold) .SetEnum("application", this.application) .List<MyLog>(); The mapping