hql

Hibernate Regex

允我心安 提交于 2019-12-28 06:53:10
问题 I am trying to build an API which can search by HQL regex keywords, EDITED: The best way to perform regex search in HQL is to use criteria, Restrictions.like() or Restrictions.ilike(). public static List<Object> createQueryAnd(Criteria cri, ArrayList<Parameters> list) { for (Parameters p : list) { String value = (String) p.value; if (value.contains("*")) { value = value.replace("*", "%"); } else { value += "%"; } Criterion c1 = Restrictions.ilike(p.property, value); cri.add(c1); } return cri

LIKE query on values of Map ElementCollection in entity in HQL

跟風遠走 提交于 2019-12-25 16:38:30
问题 I have an entity named « Form » that contains a Map « details » of (key/value)=(language code/translation) : @Entity class Form { : @ElementCollection(fetch = FetchType.EAGER) @MapKeyColumn(name = "language", length = 50, nullable = false) @MapKeyEnumerated(EnumType.STRING) @Column(name = "value", length = 150) private final Map<Language, String> details = new HashMap<Language, String> (); : } I would like to retrieve all Form records having a translation containing (!) « xxx ». The following

Calling a DB function from Hibernate

狂风中的少年 提交于 2019-12-25 07:56:38
问题 I am trying to build a job that reindexes our DB every Friday. We are using hibernate and everything I have tried so far has failed. Is there a way to execute SQL managament commands using hibernate? Such as: Session session = helper.getSession(); session.createQuery("DBCCREINDEX(User)").executeUpdate(); Or is there a better way to reindex within Hibernate? 回答1: The examples referenced below are for Oracle PL/SQL but conceptually it's the same for other databases. By "build a job" and

org.hibernate.QueryException: unexpected token: WITH in hql

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:20:02
问题 Hi am trying to join the tables with specific condition and when i executing the below query and am getting the below error org.hibernate.QueryException: unexpected token: WITH [ my HQL QUERY is below... > List results1=session.createQuery("select financialDetail from > FinancialDetail financialDetail " + > "left join financialDetail.financialClaimHeaderInfo fhdrinfo WITH (fhdrinfo.chk='224') "+ > " where financialDetail.fc=:fc") > .setParameter("fc",fc) > .list(); In the financialDetail.hbm

Composite key query using HQL and separate IdClass

二次信任 提交于 2019-12-25 04:16:21
问题 I have a hibernate entity defined with a composite key, using id class and id annoation on columns. Works fine. However I now want to do a composite key query. Select mt from MyTable mt where (mt.id, mt.column2) in (:myListOfCompositeKeys) What is the syntax using HQL, when I have defined the entity like below (not using embeddedId). @Entity @IdClass(MyKey.class) @Table(name = "MY_TABLE") public class MyTable implements Serializable { @Column(name = "ID") @Id private Long id; @Column(name =

Left join fetch with condition fails

◇◆丶佛笑我妖孽 提交于 2019-12-25 04:06:10
问题 I have the following HQL query: return entityManager().createQuery( "SELECT page FROM ProjectPage page" + " left join fetch page.categorySet as category " + " where page.id = :id " + " and category.parentCategory is null " + " and (category.status != :status_val) " ,ProjectPage.class).setParameter("id", id) .setParameter("status_val", 1).getSingleResult(); the problem is that the conditions in the where clause fails, for example, the query returns category objects whose status is 1 and

Left join fetch with condition fails

隐身守侯 提交于 2019-12-25 04:06:08
问题 I have the following HQL query: return entityManager().createQuery( "SELECT page FROM ProjectPage page" + " left join fetch page.categorySet as category " + " where page.id = :id " + " and category.parentCategory is null " + " and (category.status != :status_val) " ,ProjectPage.class).setParameter("id", id) .setParameter("status_val", 1).getSingleResult(); the problem is that the conditions in the where clause fails, for example, the query returns category objects whose status is 1 and

How to populate JTable using Hibernate?

和自甴很熟 提交于 2019-12-25 03:44:11
问题 I am creating a simple application using Swing and Hibernate. I want to populate into a JTable , the list returned by HQL query in Hibernate. Please tell me where I am doing wrong. List<Employee> employee= (List<Employee>)sess.createQuery("from Employee where ID<10").list(); String[] rows= {"Book Tile","Author","Price"}; for(Employee e:employee) { String[][] cols= {{e.getFirstName(),e.getLastName(),Double.toString(e.getSalary())},}; DefaultTableModel dtm = new DefaultTableModel(cols,rows);

How to retrive objects from one to many using HQL or Criteria API

吃可爱长大的小学妹 提交于 2019-12-25 03:43:41
问题 Started to learn hibernate with examples. I have written a class "Team" that has one to many relationship with (a Collection of) players. I need to get all the teams where player name is "X" (X is not the primary key of the Player table) where player "Y" is in I think I have to get this done by using Criteria API or the HQL. Can someone tell how I can achieve it. 回答1: Thsi will work for OneToMany relationship, ie 1 Team can Have many Players , and every no Player will be mapped to more than 1

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

ⅰ亾dé卋堺 提交于 2019-12-25 03:18:04
问题 I want to execute the below query in Hibernate? (select count(*) from login where emailid='something') + (select count(*) from user where nameid='something') 1st part OK: Query query = session.createQuery( "select count(*) from LoginClass login where login.emailid=:email); query.setString("email", "something"); Long count = (Long)query.uniqueResult(); 2nd part OK: Query query2 = session.createQuery( "select count(*) from UserClass login where name.nameid=:name); query2.setString("name",