hibernate-criteria

groovy / grails / unit testing / createCriteria.get

元气小坏坏 提交于 2019-12-04 10:34:59
问题 I can mock calls to: MyDomainClass.createCriteria().list{ eq('id',id) eq('anotherParameter',anotherParameterId) } with: def myCriteria = [ list : {Closure cls -> returnThisObject} ] MyDomainClass.metaClass.static.createCriteria = { myCriteria } as advised at: http://davistechyinfo.blogspot.com/2010/01/mocking-hibernate-criteria-in-grails.html but for: MyDomainClass.createCriteria().get{ eq('id',id) eq('anotherParameter',anotherParameterId) } This approach fails - maybe because 'get' is a

Query @ElementCollection JPA

℡╲_俬逩灬. 提交于 2019-12-04 09:15:02
I have an Entity Transaction as following : @Entity class Transaction extends AbstractEntity<Long>{ private static final long serialVersionUID = 7222139865127600245L; //other attributes @ElementCollection(fetch = FetchType.EAGER, targetClass = java.lang.String.class) @CollectionTable(name = "transaction_properties", joinColumns = @JoinColumn(name = "p_id")) @MapKeyColumn(name = "propertyKey") @Column(name = "propertyValue") private Map<String, String> properties; //getters and setters } So, my Database Table for transaction_properties is mysql> desc transaction_properties; +---------------+---

How do I resolve “Unable to resolve attribute [organizationType.id] against path” exception?

…衆ロ難τιáo~ 提交于 2019-12-04 07:08:45
I'm using Spring 3.1.1.RELEASE, Hibernate 4.1.0.Final, JUnit 4.8, and JPA 2.0 (hibernate-jpa-2.0-api). I'm trying to write a query and search based on fields of member fields. What I mean is I have this entity … @GenericGenerator(name = "uuid-strategy", strategy = "uuid.hex") @Entity @Table(name = "cb_organization", uniqueConstraints = {@UniqueConstraint(columnNames={"organization_id"})}) public class Organization implements Serializable { @Id @NotNull @GeneratedValue(generator = "uuid-strategy") @Column(name = "id") /* the database id of the Organization */ private String id; @ManyToOne

How to use key of MAP in Criteria Query?

隐身守侯 提交于 2019-12-04 03:44:44
I have a Bean like this Class TestA { Map<String,TestB> testBMap; } Class TestB { String data; ... } I want to fetch the TestA data along with the map testBMap where key ='test1' . How can i do this using Hibernate. The key must be the value of one of the persistent fields of TestB (let's says this field is names "foo"), so this code should work : Criteria criteria = session.createCriteria(TestA.class, "a"); criteria.createAlias("a.testBMap", "b"); criteria.add(Restrictions.eq("b.foo", "test1")); criteria.setFetchMode("a.testBMap", FetchMode.JOIN); return criteria.list(); YoMan78 In my case

Criteria eager fetch-joined collection to avoid n+1 selects

十年热恋 提交于 2019-12-03 12:08:18
问题 Let's say Item and Bid are entities: an Item has many Bids. They are mapped in Hibernate in a typical parent/child relationship: <class name="Item" table="ITEM"> ... <set name="bids" inverse="true"> <key column="ITEM_ID"/> <one-to-many class="Bid"/> </set> </class> How can I avoid n+1 selects when trying to access the bids of each Item after this query is executed? List<Item> items = session.createCriteria(Item.class) .createAlias("bids", "b"). .add(Restrictions.gt("b.amount", 100)). .list();

Why is criteria query deprecated in Hibernate 5?

北城以北 提交于 2019-12-03 10:42:52
问题 As we already know, criterion query is deprecated in Hibernate 5 . It was such a useful feature in the previous versions of Hibernate. And it still performs better than HQL. So what is the reason of it's deprecation in Hibernate 5 ? And also this question is not a duplicate of this question as I want to know the reason of the deprecation of criteria query. This is from here. Hibernate offers an older, legacy org.hibernate.Criteria API which should be considered deprecated. No feature

How to join Multiple tables using hibernate criteria where entity relationship is not direct?

拜拜、爱过 提交于 2019-12-03 08:20:55
I have three entities. those are: @Entity public class Organization { @Id private long id; @Column private String name; } @Entity public class Book { @Id private Long id; @Column private String name; @ManyToOne private Organization organization; } @Entity public class Account { @Id private Long id; @Column private String name; @ManyToOne private Book book; } In these three entities I would like to perform following sql: SELECT acc.name, acc.id FROM account acc JOIN book b on acc.book_id = b.id JOIN organization org on b.organization_id = org.id WHERE org.name = 'XYZ' In this case Account

Hibernate criteria query multiple criteria

自古美人都是妖i 提交于 2019-12-03 07:52:43
问题 In my current project I've faced a problem of getting entities with hibernate criteria query. I have the following entities: Professor, which contains a list of students Student, which contains a list of assignments. Assignment, which contains id of student to which it is assigned to. Now, I want to get all assignments relative to the professor, i.e. all assignments Professor assigned to his students. This query shows what I want to implement in criteria query. select * from Assigment p,

groovy / grails / unit testing / createCriteria.get

不羁岁月 提交于 2019-12-03 06:14:29
I can mock calls to: MyDomainClass.createCriteria().list{ eq('id',id) eq('anotherParameter',anotherParameterId) } with: def myCriteria = [ list : {Closure cls -> returnThisObject} ] MyDomainClass.metaClass.static.createCriteria = { myCriteria } as advised at: http://davistechyinfo.blogspot.com/2010/01/mocking-hibernate-criteria-in-grails.html but for: MyDomainClass.createCriteria().get{ eq('id',id) eq('anotherParameter',anotherParameterId) } This approach fails - maybe because 'get' is a keyword in a way 'list' is not. Can anyone advise - being able to mock this in domain classes should be

Criteria eager fetch-joined collection to avoid n+1 selects

血红的双手。 提交于 2019-12-03 02:24:44
Let's say Item and Bid are entities: an Item has many Bids. They are mapped in Hibernate in a typical parent/child relationship: <class name="Item" table="ITEM"> ... <set name="bids" inverse="true"> <key column="ITEM_ID"/> <one-to-many class="Bid"/> </set> </class> How can I avoid n+1 selects when trying to access the bids of each Item after this query is executed? List<Item> items = session.createCriteria(Item.class) .createAlias("bids", "b"). .add(Restrictions.gt("b.amount", 100)). .list(); Note I need an eager fetching for bids but with a further restriction on the collection (b.amount >