gorm

Average of subquery in GORM

爷,独闯天下 提交于 2019-12-02 09:45:52
I have a table T with columns A & C, from which I would like to retrieve an average count like so: select avg(AC) as AV from ( select A, count(1) as AC from T where C = 1 group by A ) How do I accomplish this in GORM? GRAILS version 2.2.0 I tried following the documentation but there are no good examples. I couldn't even get the subquery to work :( Update I was able to get the count portion to work. Still now sure how to get the average since I don't know how to select from a query. def tc = T.createCriteria() def tCounts = tc.buildCriteria { and { eq 'C', 1 } projections { groupProperty 'A'

Importing domain classes from GORM-standalone module into Grails

这一生的挚爱 提交于 2019-12-02 09:41:31
I have 2 pieces of my puzzle: 1) a no-Grails project named core-module with standalone GORM: dependencies { compile 'org.grails:grails-datastore-gorm-mongodb:6.0.4.RELEASE' compile 'org.grails:grails-validation:3.2.3' } and domain classes like: import grails.gorm.annotation.Entity @Entity class Module { String id String tags } the GORM-ing is initialized by Map config = new Yaml().load this.class.getResource( '/application.yml' ).text new MongoDatastore( config, Module, UserAccount ) and the domain classes are working as they would in a Grails app. 2) a Grails 3.2.3 app: dependencies { //

Count one-to-one relationship in grails

ⅰ亾dé卋堺 提交于 2019-12-02 09:11:01
I have a problem doing a query. That I want to do is access with a query to the data in my "String code" in MyDomainA through a query from MyDomainB. The relationship between the tables is unidirectional one to one. Is possible use a gorm way to do this?? Domain A: class LicenceType { String code String description Double price static constraints = { } } TABLE DOMAIN A code description A this is A B this is B C this is C Domain B: (have the unidirectional relationship) class VoiceUser { LicenceType licenceType String username String email String nameID } TABLE DOMAIN B User 1 2 3 4 That I want

How to cope with 'org.postgresql.util.PSQLException: No value specified for parameter 1'?

蹲街弑〆低调 提交于 2019-12-02 08:46:36
问题 Upon registration to my Grails app, the user receives an email with a confirmation link. Clicking that link, takes her to the according 'enable' action. This worked flawlessly. However, there now seems to be an error with a very specific token, which fails the user.save() of this snippet: assert !user.isDirty() // assertion is ok user.enabled = true user.confirmationToken = null assert user.isDirty() // assertion is ok if (user.save()) { // FAILS WITH ERROR BELOW // ... } Stacktrace: [ 16.09

or in namedQueries in Grails 2.3.8: AbstractMethodError

℡╲_俬逩灬. 提交于 2019-12-02 08:22:15
After upgrading from Grails 2.2.4 to 2.3.8 I'm getting java.lang.AbstractMethodError: grails.orm.HibernateCriteriaBuilder.or(Lgroovy/lang/Closure;)Lorg/grails/datastore/mapping/query/api/Criteria; in a query class Trip { TripParticipant driver, passenger static namedQueries = { byParticipant { UserAccount ua, name = null -> or { for( n in ( name ? [ name ] : [ 'driver', 'passenger' ] ) ) { eq "${n}.account", ua } } } } } class TripParticipant { UserAccount account boolean rated = false } any ideas? TIA UPDATE http://www.file-upload.net/download-8906460/dependency-report.txt.html is the output

Grails: Prevent cascading association between two domain classes with multiple relationships

不问归期 提交于 2019-12-02 07:41:18
Consider two domain classes; Job and Quote. A Job has many Quotes but a Job also has an accepted quote. The accepted quote is nullable and should only be set once a particular Quote has been accepted by a user. I have the relationships mapped as follows (simplified for the purpose of illustration). class Job { String title Quote acceptedQuote } class Quote { Job job BigDecimal quoteAmount } The resultant tables are exactly what I require (at least aesthetically) but the problem arises when I go and save a Quote. The Quote is saved successfully with a jobId as per the logic in my code but

gorm save method causing a select query to fire

笑着哭i 提交于 2019-12-02 06:32:55
问题 I am using grails 1.3.7 and zkoss and my domain model is as below, I load the Person entity in session 1 and make changes to it through the UI. The on press of save in session 2 I want to save the entity. So from my composer/controller I call a service method(transactional) and then do person.save(), When i see the sql queries being fired I see a query which tries to retrieve the employee object. After which the save is fired and throws a nonuniqueobjectexception Exception org.hibernate

Grails select domain objects based on an enum value in an enum list property

泄露秘密 提交于 2019-12-02 06:17:40
I'm having trouble selecting items from a list of domain objects based on a value in an enum list. My domain object looks like this: class Truck { static hasMany = [ makes: Make ] } where a Make looks like this: enum Make { KENWORTH, MACK, VOLVO } I'm not really sure how do something like Truck.findByMake(Make.MACK) to give me all of the Trucks that have this Make in their list of Makes. That call gives me this error: No property found for name [make] for class [class Truck] Any ideas? Grails 1.2.2. This one's tricky and not supported by the dynamic finders. I also don't know how to do this

Grails: changing dataSource url at runtime to achieve multi tenant database separation

白昼怎懂夜的黑 提交于 2019-12-02 05:13:43
I'm building a multi tenant application with Grails and I want to keep separate databases. I need to change the url dynamically at runtime to point GORM to different database. I have a front-end acting as a balancer distributing requests to a cluster of backend hosts. Each backend host runs a Grails 2.3.5 instance and a mysql-server with several databases (one per tenant). I would like to change dataSource dynamically so that GORM can access domain entities on the right database. Any ideas ? Thanks You can configure multiple data source in your DataSource.groovy, have a look in the blog . In

Grails 3.3.0 with PostgreSQL 10.1 gives column this_.id does not exist error

故事扮演 提交于 2019-12-02 04:12:31
I have to make a Grails 3.3.0 web interface for my internship with PostgreSQL version 10.1 as database and spring-security-core version 3.2.0. I used version 42.1.4 as a JDBC driver for PostgreSQL. I've installed PostgreSQL on my Linux laptop and created the webInterfaceDev database with the user postgres. However, every time I want to start the project I get an error that the column this_.id does not exist. This is the error that I get: 2017-11-16 14:42:21.464 ERROR --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: column this_.id does not exist Position: 8 2017-11-16 14:42:21.504