gorm

Maintaining both sides of self-referential many-to-many relationship in Grails domain object

I'm having some problems getting a many-to-many relationship working in grails. Is there anything obviously wrong with the following: class Person { static hasMany = [friends: Person] static mappedBy = [friends: 'friends'] String name List friends = [] String toString() { return this.name } } class Bo...

Grails GORM (Hibernate) query

Hello, I'm trying to do the below sql statement in GORM select * from table1 where table1.x not in (select x from table 2 where y='something'); so, I have two tables, and needs to find the entries from table 1 which are not in table 2. In Grails def xx= table2.findByY('something') def c = table1.createCriteria() def ...

Grails domain class object updating question

Hi, should always the "version" field be checked when updating a domain class object ? If so, is using a while with sleep an acceptable option ? ...

Gorm findallby date tip

Hi, any quick tip to implement findAllByGreaterThan so I can filter those records which date field is today (from 00:00 up to present). Thanks in advance ...

Is it possible for a Grails Domain to have no 'id'?

Is it possible to create a table that has no 'id'? For example, this is my domain: class SnbrActVector { int nid String term double weight static mapping = { version false id generator: 'identity' } static constraints = { } } When I run this SQL statement, it fails: insert into snbr_act_...

Maintaining the position of columns in Grails/GORM

Is there a way to fix the position of the columns in a domain? I have this domain: class SnbrActVector { int nid String term double weight static mapping = { version false id(generator: 'assigned') } static constraints = { nid(blank:false) term(blank:false) weight(blank:...

Grails- Unique and Null

Here DealerID can be nullable and CarID, TyreID are unqiue. The problem I have noticed is: Grails ignores nulls in unique constraints. ...

Grails - Need to restrict fetched rows based on condition on join table

Hi guys, I have these two domains Car and Driver which have many-to-many relationship. This association is defined in table tblCarsDrivers which has, not surprisingly, primary keys of both the tables BUT additionally also has another boolean field deleted. Herein lies the problem. When I find/get query on domain Car, I am fetched all re...

In Grails, How can I create a domain model to link two of another model?

Hey all, I'm currently trying to create a Friendship domain object to link two User objects (with a bit of additional data: createDate, confirmedStatus). My domain model looks as follows class Friendship { User userOne User userTwo Boolean confirmed Date createDate Date lastModifiedDate static belongsTo = [userOne:User , userTwo:User...

Grails saving contained object : Example from grails-samples

Hello, I was trying the grails sample programs from http://github.com/grails/grails-samples.git . It is also part of the Definitive Guide To Grails book. The steps (as per grails-samples/dgg/README.txt). Installed mySql --> created user (gtunes), db (gtunes_ch17) etc set GRAILS_HOME, PATH to grails 1.1 ver Grails upgrade grails app-r...

Persisting string array in single column

Our main domain object has multiple string[] properties (various configuration options) and we are thinking of an elegant way to persist the data. GORM creates joined table for the each array so we end up with about dozen joined tables. I wonder if it would be possible to serialize each array into single column of the main table (somew...

How to access relationship table when doing executeQuery in Grails?

Is it possible to access the relationship table when doing HQL statement? As an example, I have 3 tables: account, commitment, account_commitment. It was generated using these domains: class Account { static hasMany = [ commits : Commitment ] String name } class Commitment { static hasMany = [ actors : Account ] String ...

How to count ocurrences in 1 to many relationship in gorm - grails

Hi, I have 2 domain classes class A { .... static hasMany = [bs:B] } class B { int code .... } How can I list the number of ocurrences of all codes in B in all the A table? Something like b.each { thisb -> int ocurrences = A.bs.findAll{it == thisb}.size() ... } Thanks ...

How to implement "select sum()" in Grails

I have a relationship like this: class E { string name hasMany = [me:ME] } class M { float price } class ME { E e M m int quantity } And I'd hate to iterate to achieve this: "obtain the sum of the quantity in ME times the price of the corresponding M for a given E". Any hints on how to implement it using GORM/HQL ? Thanks...

Efficiently retrieve objects with one to many references in Grails using GORM

I'm trying to determine how to find/retrieve/load objects efficiently in terms of a.) minimizing calls to database and b.) keeping the code as elegant/simple as possible (i.e. not writing hql etc.). Assume you have two objects: public class Foo { Bar bar String badge } public class Bar { String name } Each Foo has a bar...

Grails GORM Embedded

Using GORM embedded can we add data for both the classes at once? Can the scafolding be done for these ? grails Embedded ...

Adding index key in Grails' Domain

I tried following this reference and this is now my domain's code: class SnbrActVector { long nid String term double weight static mapping = { version false nid index:'Nid_Idx' } static constraints = { term(blank:false) } } What I want is to do is to add an index key for 'nid' col...

How much of Grails GORM to test?

Is there a "best practice" or defacto standard with how much of the GORM functionality one should test in the unit/functional tests? My take is that one should probably do most of the domain testing as functional tests so that you get the full grails environment. But what do you test? Inserts, updates, deletes? Do you test constraints e...

How to do Group By in grails to order by Count(*)

How do I translate: SELECT COUNT(*) AS `count`, `a` FROM `b` GROUP BY `a` ORDER BY `a` into grails or gorm query? ...

How to get search results in grails if you have the domain (model) name stored in a string

I have a method which has domain name as a String parameter. def modelName="Equity" I want to use it like def results=modelName.findAll() Please guide me! ...