hql

Hibernate Query Language Problem

情到浓时终转凉″ 提交于 2019-12-11 13:49:23
问题 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 table. I have applied query : select distinct userName, aid, pid from ProjectAssignment Whereas the ProjectAssignment.java file has the fields in sequence aid,

NHibernate HQL Generator Caching Expression

非 Y 不嫁゛ 提交于 2019-12-11 13:07:15
问题 I have created the following NHibernate HQL generator: public class ContainsGenerator : BaseHqlGeneratorForMethod { public ContainsGenerator() { SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition(() => MyExtensions.Contains(null, null)) }; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { var exp = FormatExpression((string)((ConstantExpression

Not getting column names in the result of hql query

被刻印的时光 ゝ 提交于 2019-12-11 12:49:21
问题 I am getting records from database table using hql query in spring boot. I am returning result in json object using @ResponseBody. I am getting only data but not getting column names so i am unable to understand which column containg which data. Here is my DAO @Transactional public interface MyDaoInterface extends CrudRepository<Rating, Long>{ @Query(countByPostId) List<Rating> countByPostId(Long post_id); final String countByPostId= "select new netgloo.models.CountAndPoints(count(r.id), r

Does fetch all properties do left join under the hood?

[亡魂溺海] 提交于 2019-12-11 12:14:31
问题 My entity looks like below: to simplify I am just showing two fields. We decided to do fetch all to load all properties at once. @Entity public class Person{ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Set<PhoneNumber> phoneNumbers = new HashSet<>(0); @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "AGENCY_ID") private Agency agency; left join: (This returns duplicate records.) select person from Person person left join person.agency ag left join person

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

淺唱寂寞╮ 提交于 2019-12-11 10:14:41
问题 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

Java SQL Query - Hibernate

点点圈 提交于 2019-12-11 10:13:47
问题 So I got query that I made list from and then pass that list to another method that should print it. Query query = session.createQuery("from Osoba as o FETCH ALL PROPERTIES WHERE ((o.id) = (id_osoby)) and (LOWER(Zainteresowania.zainteresowanie) LIKE ?) and (LOWER(Zainteresowania.zainteresowanie) LIKE ?) and (LOWER(Zainteresowania.zainteresowanie) LIKE ?) and (LOWER(Zainteresowania.zainteresowanie) LIKE ?) and (LOWER(Zainteresowania.zainteresowanie) LIKE ?)"); // Query query = session

How to get only one record using hql in spring boot

核能气质少年 提交于 2019-12-11 10:02:01
问题 I am using hibernate with spring boot. I want to get next and previous record from table by passing an id. I have written a query in hql to get next and previous records from table. The problem is that i am getting all previous and all next records but i want only one previous and one last record. Here is my DAO class for next record @Transactional public interface DataDao extends CrudRepository<Data, Long> { @Query(getDataId) NextPrevData getDataId(Long post_id, Long data_id); final String

HQL combining aggregate functions

江枫思渺然 提交于 2019-12-11 09:38:02
问题 My problem is that I cannot use those two aggregate functions together like in the query: AVG(MIN(, First I need to obtain the minimum value from that entity termResultCurrent and after that the average of all the minimum values. Probably it must be changed the group by and include some other clause to fetch just the minimum value (I don't know if that is possible). Otherwise, it might be using subqueries but I had problems with the group by... I know it is quite challenging but I do

findAll() Not Returning Correct Object Type

不羁岁月 提交于 2019-12-11 08:27:53
问题 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 expected: Pilgrim's Progress However, as soon as I add another table to the criteria, instead of getting a list of ItemTags, I just get a list of generic objects. e

Does Hive support Select in Select?

给你一囗甜甜゛ 提交于 2019-12-11 08:19:23
问题 Is the code bellow in Hive possible, wich some change?: insert into table webmap select a.res reference, b.res resource, (select count(ip) from weblog where resource=a.res and referer=b.res) weight from toprefres a join toprefres b; I run that in hive-0.10.0-cdh4.5.0 and got the error: FAILED: ParseException line 3:1 cannot recognize input near 'select' 'count' '(' in expression specification What if select in select in Hive is supported! I've finally figured out the answer: insert into table