gorm

return domain objects from grails constraint validation

Is it possible to write your own validator in grails that will return a valid object? Something like: static constraints = { name(validator: {val, obj -> if (Drink.findByName(val)) return [Drink.findByName(val)] }) } In other words - if the Drink already exists in the DB, just return the existing one when someone does...

grails deleted object would be re-saved by cascade error

I have the project as set-up below. I am trying to delete a project, and I get the following: 2010-09-29 11:45:22,902 [http-8080-1] ERROR errors.GrailsExceptionResolver - deleted object would be re-saved by cascade (remove deleted object from associatio ns): [Project#204] org.hibernate.ObjectDeletedException: deleted object would be re...

Grails GORM question

Hi, I have two domain classes: class A { String Name ... } class B { A request B response ... } How can I get a list of unique As that are present as "requests" in B ? I tried def g = A.findAll("from A as e, B as r where e=r.request") But I have problems extracting the resulting objects. Thanks ...

Telling GORM not to persist a property

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. Thanks. ...

Grails: Querying Associations causes groovy.lang.MissingMethodException

Hi, I've got an issue with Grails where I have a test app with: class Artist { static constraints = { name() } static hasMany = [albums:Album] String name } class Album { static constraints = { name() } static hasMany = [ tracks : Track ] static belongsTo = [artist: Artist] String name } class Track { static constraints...

Deleting m-to-m is also trying to cascade delete a one-2-one

I have the following Domains class Committee { String name BoardCommitteeType boardCommitteeType Date dateCreated Date lastUpdated User createdBy User modifiedBy static belongsTo = [ board: Board, ] static hasMany = [ members: User ] } class User { static hasMany = [ ...

GORM createCriteria and list do not return the same results : what can I do?

I am using Nimble and Shiro for my security frameworks and I've just come accross a GORM bug. Indeed : User.createCriteria().list { maxResults 10 } returns 10 users whereas User.list(max: 10) returns 9 users ! After further investigations, I found out that createCriteria returns twice the same user (admin) because admin has 2...

Custom Insert and Update methods defeated by automatic Save

I am porting a Grails application from Oracle to MySQL database. The original Oracle version is a legacy database which uses a few complex Views leveraging Oracle's INSTEAD OF INSERT OR UPDATE feature which MySQL doesn't have. As a workaround I have implement Insert and Update methods on the Domain classes which point to these kinds of V...

delete all items from sorted set in grails

I have a grails project with a class that I can delete no problem when doing it "manually" from the controller. I use the following code. def delete = { def projectInstance = Project.get( params.id ) def employee = projectInstance.employee def projectarray = new ArrayList<Project>(); projectarray += employee.getProjects(...

Grails "render as XML" throws java.lang.NullPointerException - what am I doing wrong?

I use the following Grails code to render a collection of SomeClass-objects as XML: def someObjects = SomeClass.findAllByFoo(foo) if (someObjects) { render(contentType:"text/xml", text:someObjects as XML) } This works as expected most of the time. However, sometimes and depending on the content of someObjects the code fails with the...

grails limited table creation

Hello, I'd like to use the Grails feature for creating/updating database tables on a limited basis. Specifically, I'd like Grails to manage some tables, but not all. Is there a way to limit the tables managed by Grails or is it an all or nothing proposition? Thanks, Steve ...

GORM Querying where filter is not a direct attribute of a class.

I am trying to figure out the most efficient / effective way of performing a certain type of query using Grails GORM. This is the scenario where I want to query all of the children / linked items in a many to one relationship. This is a one way relationship whereby the many side used the id of the thing it is linked to. One example in...

Domain object referring to a reference table in Grails GORM

I have a domain object called User: class User{ String username; String firstName; String lastName; Zipcode zip; } I also have a Zip Code object: class Zipcode { String zip; String city; String state; Float lat; Float long; } The zipcode table should never be modified as it contains static reference data prepopula...

Booleans in grails aren't persisted?

Hello, I'm developing a small application on Grails 1.3.5 and I run into this very strange problem. My domain classes feature some boolean typed fields. None of these fields is persisted when creating a new instance (and saving it of course). For example, I have this domain class "Employee", defined as follows (simplified): class Emp...

grails unidirectional one-to-many

this has been bugging me, lets say i have two model, category and product class Category { static hasMany = [products : Product] String name } .. class Product { String name } now, i want to delete product, which happens to exist in many category. i came up with these lines in my product beforeDelete methods def beforeDelete =...

How to set uniqueness at DB level for a one-to-many association?

My problem is simple but I could not find any GORM syntax for this. Consider the following class: class Article { String text static hasMany = [tags: String] static constraints= { tags(unique: true) //NOT WORKING } } I want to have one unique tag name per article defined in my constraints but I cannot make it with the ...

Can't create grails Criteria query containing a belongsTo relation

Hi all, I've been trying to create a criteria builder containing a belongsTo relation and have yet to succeed. Consider the following model: class Msg { ... static belongsTo = [user: User] ... } class User { ... Organisation organisation ... } I'm trying to make the following query: Msg.createCriteria()....