hibernate-criteria

hibernate.jpa.criteria.BasicPathUsageException: Cannot join to attribute of basic type

为君一笑 提交于 2019-12-05 22:43:40
I have two tables: Tax and TaxRule . There is one column same in both table i.e TAX_RULE_ID . But don't have any Hibernate mapping like OneToOne or OneToMany . Both table looks like- TAX @Id @Column(name = "TAX_RATE_ID") private Long taxRateId; @Column(name = "TAX_RULE_ID") private Long taxRuleId; @Column(name = "TAX_TYPE") private String taxType; TAX_RULE @Id @Column(name = "TAX_RULE_ID") private Long taxRuleId; @Column(name = "TAX_CD") private String TaxCode; @Column(name = "STATE") private String state; I am trying to fetch data on the key i.e TAX_RULE_ID . This column is common in both

Hibernate Criteria: adding additional restriction to Restrictions.isEmpty

倾然丶 夕夏残阳落幕 提交于 2019-12-05 21:21:17
I have created a Hibernate (3.5) Criteria query: Criteria criteria = db.getSession().createCriteria(Vendor.class); criteria.add(Restrictions.isEmpty("models")); When executed with Criteria.list, Hibernate produces the following SQL (simplified for sake of readability): SELECT this_.* FROM VENDOR this_ left outer join MODEL models1_ ON this_.id = models1_.VENDOR_ID WHERE NOT EXISTS (SELECT 1 FROM MODEL WHERE this_.id = VENDOR_ID) What I'd like to do is add a restriction within the "not exists" part so that the SQL query would look like this SELECT this_.* FROM VENDOR this_ left outer join MODEL

Issue with selecting max id rows using criteria query / hibernate query?

一个人想着一个人 提交于 2019-12-05 21:17:19
I am unable to select the rows where TestId is max for respective student, I wrote the code as follows which does not get the required output. my code is as follows, Criteria c = sessionFactory.getCurrentSession().createCriteria(student.class).setProjection(Projections.projectionList().add(Projections.property("answer"),"answer")); c.add(Restrictions.eq("surveyId",send_Survey)); //c.add(Restrictions.eq("testId", "1" )); //c.setProjection(Projection.max("testId")); c.addOrder(Order.desc("testId")); c.add(Restrictions.eq("questionid",FinalQuestionsOne)); List<String> age=c.list(); My table

Hibernate criteria with projection not performing query for @OneToMany mapping

好久不见. 提交于 2019-12-05 14:45:24
I have a domain object, Expense, that has a field called initialFields . It's annotated as so: @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, orphanRemoval = true) @JoinTable(blah blah) private final List<Field> initialFields; Now I'm trying to use Projections in order to only pull certain fields for performance reasons, but when doing so the initialFields field is always null. It's the only OneToMany field and the only field I am trying to retrieve with the projection that is behaving this way. If I use a regular HQL query initialFields is populated appropriately, but of

hibernate update single column using criteria

别说谁变了你拦得住时间么 提交于 2019-12-05 04:52:33
I have a table that contains mamy columns and I want to update the one or few columns of the row without effecting remaining columns I can write query: update table as t set t.a=:a set t.b=:b where t.id=1 But seen I dont know which columns will be selected to update, and I think it is not a good idea to write every query for every scenarios. Well, I have to write query for every scenarios, but I am looking for a better way to update the table dynamically. I am thinking criteria would be a good choice. But the problem is that I have no idea how to write criteria update specific column. My code

select “all columns” with “group by” in hibernate criteria queries

不羁岁月 提交于 2019-12-05 01:23:15
I want to write a criteria query using "group by" and want to return all the columns. Plane sql is like this: select * from Tab group by client_name order by creation_time; I understand that it will have count(distinct client_name) number of rows. My current query which doesn't seem to give proper result is as follows: Criteria criteria = getSession(requestType).createCriteria(Tab.class); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("client_name"))); criteria.addOrder(Order.asc("creationTime")); This query returns "client_name" only. I don't want to

Use Hibernate Criteria for filtering keys and values in Map

穿精又带淫゛_ 提交于 2019-12-05 00:52:54
I have the following persisted class: public class Code { @ElementCollection(targetClass = CodeValue.class) @MapKeyClass(CodeProperty.class) @JoinTable(name="code_properties") @CreateIfNull( value = false ) private Map<CodeProperty,CodeValue> propertiesMap = new HashMap<CodeProperty, CodeValue>(); ... } public class CodeProperty { private String name; ... } public class CodeValue { private String value; ... } And I'm trying to get a list of Code filtered by some properties I have in propertiesMap (e.g. the codes where the property named "color" has the value "green". I'm using the following

Hibernate criteria upon associated objects

馋奶兔 提交于 2019-12-04 18:43:17
There is a class"Item" and it has some associated classes called Vehicle,Vmodel,Category,ItemName,Brand,SizeModel.Those each class has properites id and a name(for example Vehicle class, "vid" and "vname").Item class has itemcode. Also I need to get Item objects from a given sample Item object(called " sItem ") which equal to my sample item object's properties and my object's associated objects properties. Here is my code Session session = getSession(); List list = null; try { list = session.createCriteria(Item.class).add(Example.create(sItem)) .createCriteria("vehicle").add(Example.create

Hibernate query criteria for join between 3 tables

↘锁芯ラ 提交于 2019-12-04 18:34:18
I have a sql query: select * from A INNER JOIN B ON A.id = B.id INNER JOIN C ON B.id = C.id INNER JOIN D ON C.id = D.id where D.name = 'XYZ' and D.Sex = 'M' I have been trying to come with hibernate query criteria for the above sql, but having problems. Could anybody help out. Criteria c = session.createCriteria(A.class, "a"); .createAlias("a.b", "b") .createAlias("b.c", "c") .createAlias("c.d", "d") .add(Restrictions.eq("d.sex", "M")) .add(Restrictions.eq("d.name", "XYZ")); Francisco Spaeth On your question you want to perform a Cartesian Join , and this is not supported by Criteria, although

Hibernate Child Collection Limited When Using Left Join in Criteria

人盡茶涼 提交于 2019-12-04 11:09:30
When using hibernate criteria just altering the join type affects the results of the child collections of the root domain class. For instance, having class Parent have a one-to-many relationship with class Child with the following data: Parent | id | Name | | 1 | Parent 1 | Child | id | parent_id | Name | | 1 | 1 | Child1 | | 2 | 1 | Child2 | Using the following hibernate criteria returns the 1 parent row, and accessing the child collection results in the two rows being returned: session.createCriteria(Parent.class) .createCriteria('child', CriteriaSpecification.INNER_JOIN) .add( Restrictions