gorm

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",

class Authority is not a domain class or GORM has not been initialized correctly or has already been shutdown

孤者浪人 提交于 2019-12-07 11:12:47
问题 I'm working on a grails rest app. The grails version I'm using is 3.3.1. I'm using spring-security-rest for authorization. I've created the following classes using the s2-quickstart command. User Authority UserAuthority The app runs fine but the unit tests for the User class fail with the following error in console. java.lang.IllegalStateException: Either class [hungr.Authority] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is

Grails GORM Criteria Query Eager Fetching

﹥>﹥吖頭↗ 提交于 2019-12-07 06:43:14
问题 I have written a criteria query in a Grails service class where I expect an eager join to be performed, and to avoid lazy loading of child objects when displaying my results either as a JSON response or in my GSP. The query executed as expected (setting my hibernate.show_sql=true in my DataSource.groovy I can see the query), but when I crawl the association in my GSP, I can see that Hibernate is executing subsequent queries as if it were lazily loading the associations. I'm not convinced that

Grails - findAll Posts Created Today by User

£可爱£侵袭症+ 提交于 2019-12-07 05:31:57
问题 I have a domain object. class Post { User user String subject String body Date dateCreated } How do I go about this? Is straight GORM, HQL, or criteria the better way? I didn't know what kind of date manipulation ("today eq") would work in criteria. 回答1: I would probably make a named query class Post { User user String subject String body Date dateCreated static namedQueries = { todaysPosts { def now = new Date().clearTime() between('dateCreated', now, now+1) } } } Then you can use it like:

MongoDB issues with Grails Scaffolding (do not occur in MySQL)

倾然丶 夕夏残阳落幕 提交于 2019-12-07 04:44:23
问题 I tried using MongoDB 2.0.6 to replace MySQL 5.5.25 for a test Grails 2.1 App and am encountering some strange problems. Issues when using MongoDB but not MySQL: When using Scaffolding, I cannot get the fields to order by using static constraints When I specify inList as a constraint, I get a drop-down when using a MySQL backend, but a field when using a MongoDB backend. No * (asterisk) on fields where blank=false constraint specified. Domain Class : package study class Student { String login

Issues posting nested resource in Grails

为君一笑 提交于 2019-12-07 04:13:17
问题 I'm having issues understanding how Grails Restful controllers work. I'm attempting to make a post request (see below) to a nested resource. I'm not sure I understand what I need to change to make this work, as it seems that GET requests build the Bid's association with it's parent resource Item, but when I attempt to POST I am warned that the Item cannot be blank. Any help is appreciated! Item.groovy class Item { static hasMany = [bids:Bid] } Bid.groovy class Bid { Integer ownerId Double

What's the best way to define custom id generation as default in Grails?

不羁岁月 提交于 2019-12-07 03:38:45
问题 I want to switch my domain classes to use a variable length UUID for their ids. I don't want to simply display sequential ids on the URL for people to try and mess with. I've written a custom version of the Java UUID method to allow for variable length so I can have shorter ids for models that won't grow large. I found this thread that explained how to modify the default mapping so I can change to 'assigned'. Modify Id generation for a Grails Plugin What's the best way to also configure a

Grails GORM to return random rows from table?

天涯浪子 提交于 2019-12-07 00:05:31
问题 In my grails application I have: keywords = Keyword .findAll("from Keyword where locale = '$locale' order by rand() ", [max:20]) Assume there are thousands of rows in the table that match the above criteria. But it seems the rows that are returned from the table are not random but in the order the rows are stored in Db although within the context of 20 rows that are returned they are random. For my application to work I want this query to return completely random rows from the table like it

Telling GORM not to persist a property

ⅰ亾dé卋堺 提交于 2019-12-06 19:27:04
问题 Is there a way of telling GORM not to persist a property? I'm planning to define a confirm password property on my User class that I'll use for validation, but shouldn't be persisted. 回答1: Using transient key word GORM can be directed not to persist specific property. Following code snippets shows the use of transient proerties class Book { static transients = [ "digitalCopy" ] static constraints = { releaseDate(nullable: true) } String author String title Date releaseDate File digitalCopy }

get mapWith static domain field value from GrailsDomainClass grails

自作多情 提交于 2019-12-06 15:44:21
How can I get mapWith property of a domain class? I tried domainClass.mapWith as it's a static property of domain class.It didn't work. I also tried mappedBy but it's a different context. Any idea on how can i get mapWith value from GrailsDomainClass Below is my domain:- public class Ticket { String id List<Long> productInstanceId static hasMany = [productInstanceId:Long] static mapWith = "none" } If you are doing a direct check on a particular domain then you can fetch the static property with domain class. In your case it would be Ticket.mapWith or Ticket.class.mapWith . If you are doing a