gorm

Map of other types than Strings in Grails

I created simple domain class with map within it. class Foo { Map bar } Bar mapping will be created as sth like: create table foo_bar (bar bigint, bar_idx varchar(255), bar_elt varchar(255) not null); ...as stated in http://www.grails.org/GORM+-+Collection+Types: The static hasMany property defines the type of the eleme...

How do you disconnect an object from it's hibernate session in grails?

I'm trying to do this, but I get the error. "a different object with the same identifier value was already associated with the session" It looks like I need to remove dbObject from the hibernate session. def object = messageParserService.parseMessage(messageType, messageText) def dbObject = object.getClass().findByIdentifier(object.id...

Hibernate load function left out of grails?

I noticed that the Grails hibernate plugin does not support the hibernate load function? Does anybody know why that is? In all of the documentation that I have seen, it seems that the accepted way to delete an object from a db is to do a get() with the object id followed by a delete(). While this works it makes an unnecessary database...

How to resolve having 2 belongsTo in a single domain

I have the following domains: User, Role, Company. User and Role has m:n relationship, Company to User has 1:m, and User to Company is 1:1. I'm having problem with the definition of User domain. Here it is: class User { static hasMany = [authorities: Role ] static belongsTo = [ Role , Company ] } I would like to access the company f...

How do you persist a collection of Enums in Grails?

Any ideas on how to persist a collection of enums in Grails? Groovy enum: public enum MyEnum { AAA('Aaa'), BEE('Bee'), CEE('Cee') String description MyEnum(String description) { this.description = description } static belongsTo = [tester:Tester] } I want to use this enum in a Grails domain class. The domain class l...

How to add an index to the DB column 'class' used for inheritance in Grails?

Hi, When using table-per-hierarchy inheritance, GORM creates a 'class' column that stores the classname of instances. I want to add DB index to this column, since many of my SQL queries include where class='com.myapp.Mychildclass' . However, I didn't succeed with this code: static mapping = { columns { 'class' column:...

How to set nvarchar to a table column in GORM

How can I set the column's type to nvarchar(160)? I'm having a hard time making the sample code here relate to my target. I already tried this: String text static constraints = { text(size:1..160,blank:false) } static mapping = { text type: "nvarchar" } I'm encountering this error: Caused by: org.hibernate.MappingExcept...

Mapping multiple domain objects to the same table using GORM DSL

Hi, I'm creating a grails app over a legacy database. There is a table out of which I would like to create several different domain objects (Type1, Type2 and Type3 in my example below). The table is like this : ID TYPE DESCRIPTION 1 type1 description of a type1 object 2 type1 description of another type1 object 3 t...

Modifying object in AfterInsert / AfterUpdate

I have a domain object that holds results of a calculation based on parameters that are properties of the same domain object. I'd like to make sure that any time parameters get changed by the user, it recalculates and gets saved properly into the database. I am trying to do that with afterInsert (to make sure calculation is correct i...

Grails - Many-to-Many search

I have two domains declared in my app. class Posts { String title String content static hasMany = [tags:Tag] static constraints = { } } class Tag { String Name static belongsTo = Post static hasMany = [posts:Post] static constraints = { } String toString() { "Tag:${Name}" } } ...

Result set mapping in Grails / GORM

I want to map the result of a native SQL query to a simple bean in grails, similar to what the @SqlResultSetMapping annotation does. For example, given a query select x.foo, y.bar, z.baz from //etc... map the result to class FooBarBaz { String foo String bar String baz } Can anyone provide an example of how to do this in grai...

Querying and ordering results of a database in grails using transient fields

I'm trying to display paged data out of a grails domain object. For example: I have a domain object Employee with the properties firstName and lastName which are transient, and when invoking their setter/getter methods they encrypt/decrypt the data. The data is saved in the database in encrypted binary format, thus not sortable by those ...

Grails: Problem with nested associations in criteria builder

I have a frustrating problem with the criteria builder. I have an application in which one user has one calendar, and a calendar has many entries. Seems straightforward enough, but when I try to get the calendar entries for a given user, I can't access the user property (MissingMethodException). Here's the code: def getEntries(User user...

How to search an inner class?

I have these classes. class Author{ Person person } class Person{ String lastName String firstName String middleName } I'd like to query Person and Author. def persons = Person.findAllByLastNameiLike("${a}") but it seems I can't do def authors = Author.findAllByPerson(persons) Any ideas how I'd do this? ...

How to invalidate / refresh a domain instance association?

There is a bug in Grails preventing me from using removeFrom* when the node I'm trying to remove is extending the collection type. Removing the node directly from the association won't update the second level cache. A hasMany B Is there any way to manually invalidate or force a reload on an association cache? Invoking refresh() on...

Access Relationship Table in Grails

Hi, I have the following domains classes: class Posts{ String Name String Country static hasMany = [tags:Tags] static constraints = { } } class Tags{ String Name static belongsTo = Posts static hasMany = [posts:Posts] static constraints = { } String toString() { "${...

How to Alphabetically retrieve members of a list?

I have an organization class class Organization { hasMany = [member:Members] } class Members { belongsTo = organization } I'm printing all the members using <ol> <g:each in="${organizationInstance?.members?}" var="m"> <li><g:link controller="members" action="show" id="${m.id}">${m?.encodeAsHTML()}</g:link></li> </g:each> </ol> ...

Grails - Self-referencing relationships

Hi, When I write the following class, I get the following compilation error: could not resolve property How can I achive the following: class Employee{ String Name String Email Employee Manager static hasMany = [desginations:Designation] static constraints = { Name(unique:true) Email(unique:true) } Thanks...

Gorm findAllBy inside gsp doubt

Hi, can anybody tell me why this works <g:each var="n" in="${com.pp.News.list()}"> <h2>${n.t}</h2> <p>${n.tx}</p> </g:each> but this doesn't ? <g:set var="news" value="${com.pp.News.findAllByShow(true,[sort:'prio', order:'desc',max:5])}" /> <g:each var="n" in="news"> <h2>${n.t}</h2> <p>${n.tx}</p> </g:each> Part of the e...

Grails: Help with HQL query.

I'm not very good in SQL and HQL... I have two domains: class Hotel { String name } class Room { Hotel hotel float price } How many hotels have at least one room ? ...