createcriteria

How to Solve : org.hibernate.HibernateException: createCriteria is not valid without active transaction

旧街凉风 提交于 2019-12-11 05:05:01
问题 I'm learning Spring 4.0 + Hibernate 4.3 integration and I'm very new to both technologies. I'm getting errors after solving previous. Anyone please guide me to complete this successfully. applicationContext.xml <?xml version='1.0' encoding='UTF-8' ?> <!-- was: <?xml version="1.0" encoding="UTF-8"?> --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www

Is there a 'does not contains' functionality on a collection property of a domain object for createCriteria?

梦想与她 提交于 2019-12-08 00:57:45
问题 I have a problem similar to this. But I want a does not contain functionality. Like I have a Post domain. A Post hasMany User. What I'd like to do, using createCriteria, is something like this: def c = Post.createCriteria() def l = c.list (max: maxVar) { notContains("users", thisUser) } I tried using ne But no luck. def l = c.list (max: maxVar) { users { ne('id', thisUser.id) } } To be clear, how can I get list of all the Post whose users field which is a collection does not contain thisUser

nhibernate CreateCriteria wildcard Like when

て烟熏妆下的殇ゞ 提交于 2019-12-07 22:58:32
问题 In SQL I can write SELECT blah FROM Clients Where @p1 Like '%'+lastname+'%' How do I represent this with CreateCriteria in Nhibernate? I've tried s.CreateCriteria<Client>.Add(Restrictions.Where<Client>(c => "something".Contains(c.LastName)) but get an error System.Exception: Unrecognised method call: System.String:Boolean Contains(System.String)\r\n at NHibernate.Impl.ExpressionProcessor.ProcessCustomMethodCall(MethodCallExpression methodCallExpression) I've also tried s.CreateCriteria<Client

Grails Projections not returning all properties and not grouped

孤者浪人 提交于 2019-12-07 12:44:59
问题 How to get it so i return all of the projections from the below def c = Company.createCriteria() def a = c.list(params){ projections{ property 'id', property 'name' } } if(a.size() == 0) render "404" else { render (contentType: 'text/json'){ totalCount = a.totalCount data = a } } The result comes out like this: {"totalCount":2,"data":["company1","company2"]} Where i need it to be: {"totalCount":2,"data":[{"class":"org.example.Company","id":1,"name":"company1"},{"class":"org.example.Company",

Is there a 'does not contains' functionality on a collection property of a domain object for createCriteria?

删除回忆录丶 提交于 2019-12-06 09:32:36
I have a problem similar to this . But I want a does not contain functionality. Like I have a Post domain. A Post hasMany User. What I'd like to do, using createCriteria, is something like this: def c = Post.createCriteria() def l = c.list (max: maxVar) { notContains("users", thisUser) } I tried using ne But no luck. def l = c.list (max: maxVar) { users { ne('id', thisUser.id) } } To be clear, how can I get list of all the Post whose users field which is a collection does not contain thisUser ? You can use HQL for this List<Post> posts = Post.executeQuery("select distinct p from Post p where

NHibernate: CreateCriteria and Exists clause

隐身守侯 提交于 2019-12-04 17:29:32
问题 How can I write the following SQL using CreateCriteria: SELECT * FROM FooBar fb WHERE EXISTS (SELECT FooBarId FROM Baz b WHERE b.FooBarId = fb.Id) 回答1: Here is how you can do it: var fooBars = Session.CreateCriteria<FooBar>() .Add(Restrictions.IsNotEmpty("Bazs")).List<FooBar>(); ...assuming there is a collection property (one-to-many) "Bazs" in the FooBar object. Alternatively you could use detached criteria like that: DetachedCriteria dCriteria = DetachedCriteria.For<Baz>("baz")

NHibernate: CreateCriteria and Exists clause

流过昼夜 提交于 2019-12-03 11:23:09
How can I write the following SQL using CreateCriteria: SELECT * FROM FooBar fb WHERE EXISTS (SELECT FooBarId FROM Baz b WHERE b.FooBarId = fb.Id) Here is how you can do it: var fooBars = Session.CreateCriteria<FooBar>() .Add(Restrictions.IsNotEmpty("Bazs")).List<FooBar>(); ...assuming there is a collection property (one-to-many) "Bazs" in the FooBar object. Alternatively you could use detached criteria like that: DetachedCriteria dCriteria = DetachedCriteria.For<Baz>("baz") .SetProjection(Projections.Property("baz.FooBarId")) .Add(Restrictions.EqProperty("baz.FooBarId", "fooBar.Id")); var

CreateCriteria with projections does not select all columns

被刻印的时光 ゝ 提交于 2019-12-01 09:30:31
My Question is exactly like Grails Projections not returning all properties and not grouped I have a following criteria def sharedDocumentsInstanceList SharedDocuments.createCriteria().list(params){ createAlias('receiver', 'r') createAlias('author', 'a') eq("r.id",session.uid) projections{ groupProperty("a.id") property("a.firstName","firstName") property("a.lastName","lastName") property("a.emailAddress","email") } } Where sharedDocuments is defined as follows class SharedDocuments { Users author Users receiver Documents file } What I have seen is that sharedDocumentsInstanceList always has

Grails / GORM criteria query with hasmany String

随声附和 提交于 2019-12-01 03:22:48
I have a domain object (Cat) like this: class Cat { String name static hasMany = [ nicknames: String ] } (A cat has a name, and also has many nicknames (which are Strings)) And I am trying to query all the cats with certain nicknames. I've tried this: PagedResultList getCatsByNickname(String nickname, Map params) { PagedResultList results = Cat.createCriteria().list(params) { 'ilike'('nicknames','%'+nickname+'%') } return results } But it never returns any results. (If I change the query to just use the simple name attribute, it works finding all cats with that name, but I want to query

Grails 2.x createCriteria 'or' doesn't work for nested associations

ぃ、小莉子 提交于 2019-11-30 14:49:00
It seems that in Grails 2.x, if you have a domain class association, and you try to run a createCriteria using or on that relation + another query, the or will ignore the other query and just use the results of the nested association. I realize this may be a little confusing, so here is an example: class Passenger { Long id Boolean isDriving } class Car { Long id Passenger passenger Boolean isMoving static constraints = { passenger nullable: true } } and a test: class CarIntegrationTests { @Test void testCar() { Passenger passenger1 = new Passenger(isDriving: true) passenger1.save() Car car1 =