hql

What's wrong with this HQL? “No data type for node”

两盒软妹~` 提交于 2019-12-22 01:50:40
问题 session.createQuery("Select attribute from GoodsSection tgs " + "join gs.ascendants ags join ags.attributes attribute " + "where attribute.outerId = :outerId and tgs = :section ") .setString("outerId", pOuterId) .setEntity("section", section) .setMaxResults(1) .uniqueResult(); Looks fine to me, but the result is java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode \-[IDENT] IdentNode: 'attribute' {originalText=attribute} at org.hibernate.hql.ast.tree

Hibernate QueryTranslatorImpl HQL AST parsing performance

倾然丶 夕夏残阳落幕 提交于 2019-12-22 00:28:46
问题 I'm facing performance issues executing standard spring-data-jpa findAll queries using @NamedEntityGraph When I examine the logs, I see the following statements: 2016-10-26 09:46:25,681 DEBUG [http-nio-8080-exec-1] CriteriaQueryImpl: Rendered criteria query -> select generatedAlias0 from Patient as generatedAlias0 order by generatedAlias0.id asc 2016-10-26 09:46:25,681 DEBUG [http-nio-8080-exec-1] CriteriaQueryImpl: Rendered criteria query -> select count(generatedAlias0) from Patient as

Nhibernate ICriteria and Using Lambda Expressions in queries

自古美人都是妖i 提交于 2019-12-21 21:16:00
问题 hi i am new in NHibernate and i am a little confused. Suppose we have a product table. Let the product table have 2 columns price1 and price2. then i may query mapped product entities via HQL as follows: string queryString = @"from product p where p.price1 = p.price2 + 100 "; IList result = session.CreateQuery(queryString).List(); How can i achieve that via ICriteria API. i know it's absurd but i am trying sth like that: session.CreateCriteria(typeof(product)) .Add(Expression.Eq("price1",

Hibernate - HQL to fetch a collection from Unidirectional OneToMany relationship

让人想犯罪 __ 提交于 2019-12-21 09:26:07
问题 I have an Class with a unidirectional one to many relationship as follows: public class Order { @OneToMany(cascade = CascadeType.ALL) @JoinTable(name="order_item", joinColumns={@JoinColumn(name="order_id")}, inverseJoinColumns={@JoinColumn(name="item_id")}) public Set<Item> getItems() { return items; } } Normally getting the contents of this order is straightforward: List<Item> items = order.getItems(); But for whatever reason I might want to filter my results in some way and retrieve only

Hibernate: how to make EXISTS query? (not subquery)

天大地大妈咪最大 提交于 2019-12-21 09:19:09
问题 For example: EXISTS ( SELECT * FROM [table] WHERE ... ) How to make such query using Hibernate? 回答1: If your goal is inspect some set on emptiness, you may use simple HQL query: boolean exists = (Long) session.createQuery("select count(*) from PersistentEntity where ...").uniqueResult() > 0 回答2: HQL doesn't allow to use exists statement. UPD Starting from Hibernate 5 it supports it as a predicate in WHERE You can use several approaches: For Hibrnate 5: you can use subquery with the same table

HQL: Hibernate query with ManyToMany

依然范特西╮ 提交于 2019-12-21 07:55:13
问题 I have a question with HQL query and hibernate. I have a user class and a role class. A user can have many roles. So I have a ManyToMany relatation like this: In user class: @ManyToMany(fetch = FetchType.LAZY) @oinTable(name = "PORTAIL_USERROLE", joinColumns = { @JoinColumn(name = "USERID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLE", nullable = false, updatable = false) }) public Set<Portailrole> getPortailroles() { return this.portailroles; } In

java hibernate: selecting the discriminator column in polymorphic hql query

那年仲夏 提交于 2019-12-21 07:24:12
问题 In hibernate, I want to select the discriminator value. Something like select discriminator, id, name, age from Animal The idea is to send the result of this query to the client side, so that I can display a different icon based on the value of the discriminator column (i.e. cat, dog, elephant, etc). Is that possible? How? 回答1: You can do it as follows: select a.class, a.id, a.name, a.age from Animal a From Hibernate Documentation: The special property class accesses the discriminator value

New Object with HQL - NPE on StandardAnsiSqlAggregationFunctions, determineJdbcTypeCode

爱⌒轻易说出口 提交于 2019-12-21 06:38:20
问题 I know this has been asked a lot, but I seem to be having a different problem. I saw that there is a bug in Hibernate that struggles with a SumFunction ignoring custom user types, but I'm not using a custom user type to my knowledge. I'm basically trying to create a new object that is a roll-up of an existing mapping bean, however I receive a NullPointerException against some Hibernate dialect function. I tried using both Double and BigDecimal as my value field type, but both provide me the

JPA with Hibernate - Many to Many relationship, fetching all data

为君一笑 提交于 2019-12-21 06:28:08
问题 I have many to many relation ship between User and Roles. For example public class User { @Id private Integer id; @ManyToMany @JoinTable(name = "APP_USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") }) private List<Role> roles = new ArrayList<Role>(); } @Entity public class Role { @Id private Integer id; @ManyToMany(mappedBy = "roles") private List<User> users = new ArrayList<User>(); } My requirement is to fetch all users in the

How hibernate works with HQL query if the Transformer is not explicit declared

妖精的绣舞 提交于 2019-12-21 06:25:10
问题 I don't know where I can find the implementation mechanism of hibernate. I have a lot of questions about hibernate but we can start them from this one: If there is a HQL like this: from B b where b.x =: x and b.y =: y And query code like this: Query query = session.createQuery(hql.toString()); What is the default transformer to set all of the fields into B? I found this even doesn't need setter or getter to set values. Or say, what is the differece between it and this one: Query query =