hql

HQL error: with-clause referenced two different from-clause elements

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting started with Hibernate and I am using HQL, using some joins to retrieve data from the db but getting this error, any help on how to solve this is appreciated. Field.hbm.xml file: <id name="id" type="string"> <column name="field_map_cd" /> <generator class="assigned"></generator> </id> Rule.hbm.xml file: <many-to-one name="src_field_map" column="field_map_cd" not-null="true" insert="false" update="false"/> <many-to-one name="tgt_field_map" column="field_map_cd" not-null="true" insert="false" update="false"/> HQL query: select t

HQL with Null check for one-to-one relation

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following one-to-one relation in Hibernate (that could be null): <one-to-one name="details" class="com.example.Details" lazy="false" cascade="all"/> I am trying to select all entities that have non-null details with HQL: from Entity e where e.details is not null but this returns all entities, no matter whether details are null or not. What would be a correct HQL then? 回答1: Ok I found the solution: select e from Entity e join e.details d where d is not null 回答2: Let's suppose this one-to-one relation is part of the mapping of

New Object with HQL - NPE on StandardAnsiSqlAggregationFunctions, determineJdbcTypeCode

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 same error message on deployment. Please help!

Hibernate QueryTranslatorImpl HQL AST parsing performance

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: 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

How to write a query in hibernate for count(*)

我的梦境 提交于 2019-12-03 08:22:00
问题 I want to execute the below query in Hibernate ? select count(*) from login where emailid='something' and password='something' 回答1: Suppose your login table is mapped by a LoginClass class, with emailid and password instance variables. Then you'll execute something like: Query query = session.createQuery( "select count(*) from LoginClass login where login.emailid=:email and login.password=:password"); query.setString("email", "something"); query.setString("password", "password"); Long count =

mybatis与hibernate区别

假如想象 提交于 2019-12-03 08:16:38
以前没怎么用过mybatis,只知道与hibernate一样是个orm数据库框架。随着使用熟练度的增加,发现它与hibernate区别是非常大的,结合至今为止的经验,总结出以下几点: 1.hibernate是全自动,而mybatis是半自动。 hibernate完全可以通过对象关系模型实现对数据库的操作,拥有完整的JavaBean对象与数据库的映射结构来自动生成sql。而mybatis仅有基本的字段映射,对象数据以及对象实际关系仍然需要通过手写sql来实现和管理。 2.hibernate数据库移植性远大于mybatis。 hibernate通过它强大的映射结构和hql语言,大大降低了对象与数据库(oracle、mysql等)的耦合性,而mybatis由于需要手写sql,因此与数据库的耦合性直接取决于程序员写sql的方法,如果sql不具通用性而用了很多某数据库特性的sql语句的话,移植性也会随之降低很多,成本很高。 3.hibernate拥有完整的日志系统,mybatis则欠缺一些。 hibernate日志系统非常健全,涉及广泛,包括:sql记录、关系异常、优化警告、缓存提示、脏数据警告等;而mybatis则除了基本记录功能外,功能薄弱很多。 4.mybatis相比hibernate需要关心很多细节 hibernate配置要比mybatis复杂的多,学习成本也比mybatis高

从JDBC到hibernate再到mybatis之路

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 08:14:39
一、传统的JDBC编程   在java开发中,以前都是通过JDBC(Java Data Base Connectivity)与数据库打交道的,至少在ORM(Object Relational Mapping)框架没出现之前是这样,目前常用的ORM框架有JPA、hibernate、mybatis、spring jdbc等,我一开始也是使用JDBC编程,后面开始使用hibernate,有一次开发一个CRM管理系统使用的是Spring JDBC操作数据库,但个人还是不太喜欢这个框架,本人目前使用的最多还是通过mybatis操作数据库,尽管我现在使用的是Spring boot开发,继承了JPA来操作数据库,但是实体类和dao、service、controller层的基本CRUD操作还是通过hibernate代码工具自动生成的,其他操作都是通过mybatis自己编写SQL语句来操作的,因此本文只提JDBC到hibernate再到mybatis的一个过程。 1、什么是JDBC   JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,是用Java语言编写的类和接口组成的,可以为多种关系型数据库提供统一访问的接口。JDBC提供了一种基准,说白了,也就是sun公司为各大数据库厂商的关系型数据库连接java所制定的规范

Parameterizing a HQL IN clause using HqlBasedQuery?

亡梦爱人 提交于 2019-12-03 07:46:36
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 user interface, not known at compile time object[] productIds = {1, 17, 36, ... }; string hqlQuery = @

How to get last record from Mysql using Hibernate?

大兔子大兔子 提交于 2019-12-03 07:24:19
问题 List<Lahetys> last = session.createQuery("from lahetys order by lahetysNro DESC LIMIT 1").list(); and in the log I got: INFO: Hibernate: select from order by lahetysNro DESC LIMIT 1 WARN: SQL Error: 1064, SQLState: 42000 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from order by lahetysNro DESC LIMIT 1' at line 1 What has happend to "from LAHETYS"? What is the best practice to handle that with HQL

Hibernate Named Query Using Like and % % operators?

会有一股神秘感。 提交于 2019-12-03 06:32:48
问题 In my Hibernate JPA Sample code.. public List<AttendeesVO> addAttendees(String searchKeyword) { TypedQuery<AttendeesVO> query = entityManager.createQuery(" select at from AttendeesVO at where at.user.firstName LIKE :searchKeyword",AttendeesVO.class); query.setParameter("searchKeyword", searchKeyword+"%"); return query.getResultList(); } it is working fine when giving entire String firstName=Narasimham But it is not working when we give any character of Narasimham i.e a or n Actually my