deals with issues related to the definitions of domain model
Questions tagged [grails-domain-class]
689 questions
8
votes
4 answers
Do grails domain classes have to be tied to a database?
I am a complete noob when it comes to grails (and still very noobish when it comes to groovy) so I apologise if this is a dumb question.
I am building a simple web app and I want to control portions of the domain in my app based on file system…

Michael Rutherfurd
- 13,815
- 5
- 29
- 40
8
votes
1 answer
What is the best way to declare sorted association in grails domain classes?
It seems that there are two different ways of declaring sorted associations in Grails :
Method 1 (see here) using default sort order
class Book {
String title
}
class Author {
static hasMany = [books : Book]
static mapping = { books sort:…

fabien7474
- 16,300
- 22
- 96
- 124
8
votes
5 answers
Gorm mapping for inheritance
I'm facing a issue regarding inheritance in Grails.
I have a domain class Person.grooy:
class Person{
String name
String contactNumber
Address address
}
Now I'm extending Person.groovy for Employee and Customer like:
class Employee…

Yogesh
- 470
- 4
- 17
8
votes
3 answers
Setting default value for Date field in Grails Domain Class
I'm trying to set a default value for a Date field in a Domain class.
I can use defaultValue in the mapping configuration but it doesn't work with Date fields (I've tried it on String and Integer and it works fine).
This is an example:
class…

mathifonseca
- 1,465
- 1
- 15
- 17
8
votes
2 answers
Override Grails dateCreated and lastUpdated for test data only?
I have several Grails 2.1 domain classes that include dateCreated and lastUpdated fields that GORM manages automatically, eg:
class Person {
Date dateCreated
Date lastUpdated
String name
}
I want Grails to automatically fill in these…

Dan Vinton
- 26,401
- 9
- 37
- 79
7
votes
3 answers
Using JSON to create an object in Groovy/Grails
I have a Groovy/Grails website that is being used to send data to Android clients via JSON. I have created both the Android client and the Groovy/Grails website; and they can output the same objects in JSON.
I can successfully create the respective…

chrisburke.io
- 1,497
- 2
- 17
- 26
7
votes
3 answers
Grails/Hibernate: No row with the given identifier exists
I have a domain as follow:
class Author {
String id
static hasMany = [accounts: Account]
static belongsTo = Account
static mapping = {
accounts joinTable: [name: "SOMETABLE", key: 'SOMEFIELD'],
…

user2679352
- 81
- 1
- 2
- 5
7
votes
2 answers
How can I duplicate a domain object in Grails?
I want to make a copy of a domain object. What is the simplest way to accomplish this?
I realize I could create a new record, and then iterate over each of the fields copying the data field-by-field - but I figured there must be an easier way to do…

Eduard
- 3,536
- 1
- 20
- 27
7
votes
3 answers
Grails - how execute code before every save?
Is there a good/standard way to execute some common code before every save() invocation on domain classes?
For example, my domain
class Page {
String url
Boolean processed
Date date
Integer urlCrc
}
My form has only 3 first…

mrok
- 2,680
- 3
- 27
- 46
7
votes
2 answers
Grails conditional nullable validation or custom validator with nullable option
I have a form to create a place. Depending of the country, the province (state, region) field is required or not.
When is not required, I want to be null, not empty string. I have code that makes all empty form fields, null:
def newparams = [:]
…

Eduard
- 3,536
- 1
- 20
- 27
6
votes
1 answer
How can I have an optional one-to-one relationship in GORM?
I have 2 objects, ObjectA and ObjectB.
When ObjectA gets created, ObjectB doesn't (and can't, due to not having the data yet) exist yet.
Once ObjectB is created, it needs to have a corresponding ObjectA attached to it if an appropriate one exists.…

cdeszaq
- 30,869
- 25
- 117
- 173
6
votes
0 answers
Should I convert my Grails domain relations to use Hibernate Bags?
In Grails 1.3.7 I've spent quite some time to convert my domain class relations according to Burt's suggestions in http://www.infoq.com/presentations/GORM-Performance
Now, Grails 2 supports Hibernate's Bags and I am considering to revert my changes…

user569825
- 2,369
- 1
- 25
- 45
6
votes
4 answers
getting grails 2.0.0M1 config info in domain object, and static scope?
How do I get to the Config.groovy information from a domain object, or from a static scope? I'm using ConfigurationHolder.config.* now, but that and ApplicationHolder are deprecated so I'd like to 'do it right' ... but the grailsApplication object…

Wayne
- 1,075
- 1
- 10
- 21
6
votes
1 answer
Grails, how to find by a record by its foreign key
I have two domains that are a part of a one-to-many relations ship. I was wondering how i can query the child for the parents FK? bellow is the psuedo-code for parent/child
Parent:
class AlumProfile {
String firstName
String lastName
…

jason
- 3,821
- 10
- 63
- 120
6
votes
1 answer
Class 'myClassName' already exists in package 'myPackageName'
I suddenly started facing a strange issue while working on my Grails application using IntelliJ. I have different domain classes and some other classes under src/groovy. When I open a class file to make some changes, I get an error that this class…

Bilal Ahmed Yaseen
- 2,506
- 2
- 23
- 48