gorm

many-to-many not persisting in gorm/grails app

I have roughly the following in my grails 1.1 app class AppCategory { static belongsTo = App static hasMany = [ apps: App ] String name } class App { static hasMany = [ categories: AppCategory] String name } App app = new App() AppCategory appCat = AppCategory.findByName('blah') app.addToCategories(appCat) app.sa...

Why does findAllBy* fail when using three conditions in Grails/GORM?

Consider the following usages of the Grails/GORM dynamic finder method findAllBy*: def foo1 = Foo.findAllByYear(yyyy) def foo2 = Foo.findAllByMonth(mm) def foo3 = Foo.findAllByDay(dd) def foo4 = Foo.findAllByYearAndMonth(yyyy, mm) def foo5 = Foo.findAllByYearAndDay(yyyy, dd) def foo6 = Foo.findAllByYearAndMonthAndDay(yyyy, mm, dd) prin...

Grails validation of a list objects

I'm trying to get grails to validate the contents of a List of objects, might be easier if I show the code first: class Item { Contact recipient = new Contact() List extraRecipients = [] static hasMany = [ extraRecipients:Contact ] static constraints = {} static embedded = ['recipient'] } class Contact { Str...

Grails belongsTo, should I ?

Hi, let's go straight to the problems (with Grails 1.1.1, it should work on previous one) I have 2 domains ie: User and Detail like this : Class User { String userName ; ..... // another fields static hasMany = [details:Detail]; } Class Detail{ String detailName ; ... // another fields static belongsTo = [user:Use...

How do I handle an empty List in Grails/GORM?

I'm trying to get a one-to-many relationship working with grails/gorm. I don't understand how to handle an empty list. Here is my domain class: class Parent { List children static hasMany = [children: Children] } Here is my test: void testEmptyChildren() { def parent = new Parent() assert 0, parent.children.size() }...

findAll() Not Returning Correct Object Type

ItemTag objects contain an Item object and a Tag object. (These are Java domain objects.) This simple query works as expected. I get back a list ItemTags and can do all the wonderful things that ItemTags are supposed to do: def theTags1 = ItemTag.findAll("from ItemTag b") For example: println(theTags1[0].tag.tag) gives me this as...

How to model a Friend - Friendship relationship in Grails

Hi! How would you model a friend - friendship relationship in Grails? Until now my User class had many followers class User { //Searchable plugin static searchable = true String userId String password boolean enabled = true // For Spring Security plugin's user registration. String email String userRealName boolean emailShow Date dat...

How to catch error in addToTag() [grails]

Hi, I have 2 domains .. master and details. Master{ String masterName; static hasMany=[details:Detail] } Detail { String detailName ; static belongsTo =[master:Master]; } I have form that handle the save def save = { ..... def master = new Master(params); params.detailsName.eachWithIndex(dtName, index -> def detail =...

Annotations to a grails relationship?

Looking for a way to include a conditional reference attached to a relation between two objects, for example class Person { String firstName String lastName static hasMany = [ readyNow: Role, readyLater : Role, emergencyReplacement: Role] static belongsTo = Role static constraints = { } String toString() { return firstName + " " + l...

Storing and editing key/value pairs in Grails?

I have a domain object in Grails that needs to store a set of key/value pairs for each instance. There should never be more then about 10 pairs. The users of the application have to be able to edit these key/value pairs. Right now I'm looking at storing the data in a HashMap for each instance of the domain class. While I think this will ...

Issue with multiple hasMany relationships to the same domain class when using composite id

I am getting this exception: org.hibernate.MappingException: collection foreign key mapping has wrong number of columns: Room.cellsOrig type: component[locationX,locationY] class Room implements Serializable { Integer locationX; Integer locationY; List cellsOrig = [] List cells = [] static hasMany = [cellsOrig: Cell...

GRAILS: Find all children in a self-referenced one-to-many relationship

In grails, How would one find all the children in a one-to-many relationship e.g., class Employee { static hasMany = [ subordinates: Employee ] static belongsTo = [ manager: Employee ] } Using a single manager, how would one get the subordinates of all subordinates (like traversing a object graph)? ...

GORM refresh() method not getting latest data from database

After saving a changed user name (using flush:true), the following expression evaluates to false: User.get(u.getId()).name == u.refresh().name The left hand side picks up the changed user name while the right hand side return the "old" value. Ideas? Refreshing the "u" reference in the next HTTP request appears to work. ...

Grails Hibernate Session Read Only

Hi. I have two grails servers: Server - has read/write access to the database Web - has read-only access to the database, and for every write it sends a request to the server The problem: How do I make the Web's domain objects read only in one place (config file) for the entire run of the application, instead of writing caching: 'rea...

Eager Loading with Many-to-Many relationship - Grails (GORM)

Each book can have many authors. And each author can author many books. class Book { static belongsTo = Author static hasMany = [authors:Author] } class Author { static hasMany = [books:Book] } Now when can I do: def book = Book.get(id) def authors = book.authors Now I am thinking I should be able to take each author and ...

Grails and Hibernate's Lazy Initialization Exception

Where are the most common places where you've gotten an org.hibernate.LazyInitializationException in Grails, what was the cause and how did you solve it ? I think this one exception comes up a lot for novice, so if you'd provide more examples, it would be great. ...

How to setup one-to-many unidirectional mapping for grails application on GAE ?

I try to perform testing on one-to-many unidirectional mapping for grails application on google app engine (GAE) using JPA. The one-to-many unidirectional mapping I attempt to define is between User and Role class. Unfortunately, I am stuck. Just curious is there any developer out there able to make it work successfully. Following is my...

Groovy domain mapping

Hi! I have a to save a pdf report into an Oracle DB. The report's dataType is a byteArray. The domain definition is as follows: static constraints = { report(nullable:false) company(nullable:false) month(nullable:false) } byte[] report Company company Date month } Unfortunately this defines in the Oracle DB a field whic...

GORM Hibernate query

Hi, I have the following Grails domain objects class ProductType { String name static hasMany = [attributes: Attribute] } class Attribute { Boolean mandatory = false Integer seq static belongsTo = [productType: ProductType] } I would like to get all ProductTypes and their mandatory Attributes. Furthermore, I'd ...

eager-loading queries with GORM/Hibernate

Hi, My Grails app has the following domain objects class ProductType { String name static hasMany = [attributes: Attribute] } class Attribute { String name static belongsTo = [productType: ProductType] } My DB has 7 ProductTypes and each of those has 3 Attributes. If I execute the query: def results = Product...