gorm

Grails: use domain method in named query

Hi, in my domain model, I have a method that does something with my data. e.g. class Person { String lastname String firstname String bigname() { return lastname.toUpperCase() } static namedQueries = { withBigname { name -> eq(this.bigname(), name) } } } I want to use t...

Grails Integration testing: problems with get

Hi, I'm trying to write a simple integration test, but having some trouble with Domain Objects. I've read on unit testing but can't figure it out. This is my simple test: User user = User.get(1) controller.params.userid = "1" controller.session.user = user controller.save(); The error message is: groovy.lang.Mis...

Is it possible to use a JNDI dataSource read only in Grails?

Hi, I need to add a JNDI datasource from a legacy database to my Grails (1.2.2) application. So far, the resource is added to my Tomcat (5.5) and DataSource.groovy contains: development { dataSource { jndiName = "jdbc/lrc_legacy_db" } } I also created some domain objects mapping the different tables to comfortably load...

Grails, groovy: combine GORM dynamic methods - findAllBy and OrderBy

assuming the following example: I have a User class and a Item class and a user can have many items 1) Is there a combined dynamic method to get all the items for a user and also sort them after a Property? I have a controller action that gets the items for a user and send them to the view, and the view will render them all with < g:e...

GORM 1:N Association Cascades Delete Without belongsTo!

I would like to create a one-to-many association that does not cascade deletes. Reading the Grails Reference it says The default cascading behaviour is to cascade saves and updates, but not deletes unless a belongsTo is also specified That isn't the behavior I'm seeing. With the following class implementations I get cascaded updat...

Grails hasMany: when child is updated, parent's version changes

I am using Grails and am quite surprised by the way hasMany relationships work. I have a typical hasMany relationship where the parent id is in the child table. When I insert a child and try to save it through the parent object, the parent object's version id gets incremented. My question is: Why should the parent's version id change whe...

Grails: findAllBy dynamic method - advanced sort property

I have a User class and a Item class and a user can have multiple items. I want to select some users based on other property using finndAllByProperty and adding the pagination parameters (see http://www.grails.org/doc/1.2.2/ref/Domain%20Classes/findAllBy.html .) The problem is that I want to sort the result based on how many items ea...

groovy static blocks for relationship definition

I have a couple of domain classes defined, Employee and EmployeeDesiredSkill, Employee has static hasMany = [employeeSkill:EmployeeDesiredSkill] and EmployeeDesiredSkill has static belongsTo = [employee:Employee] Yet groovyc is giving me a bunch of errors like the following: [groovyc] Compiling 15 source files to C:\dev\JavaTes...

Using groupProperty and countDistinct in Grails Criteria

I'm using Grails 1.2.4. I would like to know on how can I sort by "countDistinct" (descending) and with groupProperty inside a projections. Here are my domains: class Transaction { static belongsTo = [ customer : Customer, product : Product ] Date transactionDate = new Date() static constraints = { transactionDat...

Grails domain class query - how can I find by fields that link to another domain class?

Hello, Lets say I have two domain classes: class User { String name Role role } class Role { String name static belongsTo = [user: User] } and I create some records: def r1 = new Role(name: "role1").save() def r2 = new Role(name: "role2").save() new User(name: "user1", role: r1).save() new User(name: "user2", role: r2).save...

grails domain class validator + set unique constraint according to field values ?

Hi, Is there a way to write a custom validator that will perform different validations according to field values? For example class myModel{ A a; B b; String prop static belongsTo:[m:myModel] constraints{ prop(validator:{ val,obj-> if (obj.a== null){ unique:[b,prop] ...

Need help improving the performance of large datasets in grails.

This solution works but performance is lower than expected. A query returning 200K rows takes several minutes and pegs the CPU on my dev box. Running the same* query in query analyzer returns all results in < 1 minute. Class MyController { def index = {...} ... def csv = { ... def rs = DomainClass.createCritera().scroll {} ...

Is a variable declaration in grails the same as a belongsTo relationship?

Hello all, I am trying to set up a few domain classes. I will explain it in english, and I am wondering how the domain would be set up in grails. Capitalized words are my domains An Employee has an Education. An Employee has many Employer (past and present). An Employee had one or many Project for each Employer. Project have a Role, Cl...

In grails, why do I have to create a variable for criteria?

I can write: def c = Transaction.createCriteria() def transactions = c.list { projections { groupProperty("product") countDistinct("id") } maxResults(pageBlock) firstResult(pageIndex) } But can't write this: def transactions = Transaction.createCriteria() .list { projections { groupPropert...

Grails Enum Mapping

in Grails, Is there a way to limit the size of the column to which the enum is mapped. In the following example, i would like the column type to be char(2) enum FooStatus { BAR('br'), TAR('tr') final static String id } class Foo { FooStatus status static constraints = { status(inList:FooStatus.values()*.id,size...

Grails: No signature of method findAll() is applicable for argument types: String, ArrayList

I'm new to grails and receive the following error: No signature of method: Something.findAll() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [from Something AS s WHERE s.some_number LIKE ?, [%asdf%]]" The error occurs when I run test-app. It occurs in the following place: SomethingVO[] findBySomeN...

Grails: Is there a way to have findAll() without a query but with pagination and sorting?

As I noticed in the answers of another question there are a few problems when testing finder methods in GORM. I want to get all objects from Something and have support for sorting and pagination, so I wrote this: SomethingListVO findAllSomethings(int offset = 0, int limit = 50) { def somethingCount = Something.count() def some...

Grails relationships with static mapped tables

For the life of me I cannot seem to get relationships to work on mapped tables with Grails. I have two domains I am trying to join, Resources and Cassettes. A Resource can have many Cassettes. If i run the code below using scaffolding I get an error "Unknown column 'this_.cassette_id' in 'field list'". If i try to define the cassette_i...

does it make sense to cascade "up" to owners in belongsTo relationship?

I have a Skill class, which hasMany RoleSkills. I have a RoleSkills class which belongsTo Role and Skill I have a Role class which hasMany RoleSkills For Role, I have a mapping that cascades operations to RoleSkills. The question is, does it make sense for RoleSkills to "cascade" back to Skill? I basically want to have a RoleSkill cr...

gorm and cloning objects

I have an object foo, foo has a collection bars and each bar has a collection of baz class foo { static hasMany = [ bars : Bar ] } class bar { static belongsTo = [ foo : Foo ] static hasMany = [ bazs : Baz ] } class baz { static belongsTo = [ bar : Bar ] } I was trying to create and save the foo structure this wa...