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...
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...
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...
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...
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...
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 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...
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...
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...
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}"
}
}
...
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...
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 ...
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...
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?
...
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...
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()
{
"${...
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>
...
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...
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...
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 ?
...