grails-domain-class

Grails Integration Test Does NOT Rollback

最后都变了- 提交于 2019-12-06 05:12:01
问题 I'm learning grails from the book "Grails In Action" and I'm trying to run integration tests from the examples. In the book it says that each integration test function should roll back its operations as each test finishes. It is NOT rolling back each transaction (as when I finish the database is dirty). I tried to find out why and found found a property called "transactional". Allegedly you set this property to true and it will make the test case transactional, but it doesn't appear to change

Setting default value for Date field in Grails Domain Class

笑着哭i 提交于 2019-12-06 02:54:18
问题 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 Something { Date myField static mapping = { myField defaultValue: new Date() } } This code fails because the CREATE statement that Hibernate generates is incorrect. It is something like: ... my_field datetime default Mon Nov 25 17:59:08 UYST 2013 not null

Grails conditional nullable validation or custom validator with nullable option

与世无争的帅哥 提交于 2019-12-06 01:47:15
问题 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 = [:] place = new Place() params.each() { k, v -> if (v instanceof String && place.hasProperty(k)) { if (!v.trim().length()) { newparams[k] = null } else { newparams[k] = v } } } place = new Place(newparams) place.validate() Now, in the place domain, I have

Grails - sort by the domain relation attribute (using createCriteria())

落爺英雄遲暮 提交于 2019-12-05 21:46:17
I have two domain classes with 1:n relationship: import Action class Task { Action actionParent String taskName } and class Action { String actionName } I have the list of Tasks where I have the column "Action name", I would like to sort this column by Action.actionName. Now I'm using the createCriteria() method [I need to use it because I have more logic for filtering and sorting...], but I'm able to sort only by "Action.id". This method looks like: def criteria = Task.createCriteria(); taskList = criteria.list { if(parameters.max != null) maxResults(parameters.max) if(parameters.offset !=

GORM: What is reference:true in Grails domain class mapping block?

落爺英雄遲暮 提交于 2019-12-05 13:08:19
public class Address { static mapWith = "mongo" Region region; Zone zone; static mapping = { id generator: 'identity' region reference:true zone reference:true } } I'm interested in knowing what reference:true does. In my experience, leaving it off gives exactly the same result except there's no DBRef in the actual mongo document. It looks like reference controlls how documents are linked. When true , the related documents are referenced by db-refs , if false , GORM inserts simple id , aka Manual references in mongo This means that those properties will be stored on your Address record by

Grails Scaffolding - define possible values for this property of a domain class

一个人想着一个人 提交于 2019-12-05 07:49:41
I am new to Grails. I have a Person domain class as : class Person { String firstName String lastName String gender Date dateOfBirth } And wondering if I can define possible values for a property - say gender as {M, F, U} so that these three values will be listed in combo box when using dynamic scaffolding for Person controller. Here I just wanted to know if there is such feature in Grails framework? If such feature exists , then how can I use it? From the documentation http://grails.org/doc/latest/guide/scaffolding.html , you should be able to use an inList constraint: class Person { String

Grails Domain Class : hasOne, hasMany without belongsTo

放肆的年华 提交于 2019-12-05 06:50:34
I am new to Grails. Can I use "hasOne" or "hasMany" without using "belongsTo" to another domain-class? Thanks in advance. Yes, you can. See examples in Grails doc: http://grails.org/doc/2.3.8/guide/GORM.html#manyToOneAndOneToOne hasMany (without belongsTo) example from the doc: A one-to-many relationship is when one class, example Author, has many instances of another class, example Book. With Grails you define such a relationship with the hasMany setting: class Author { static hasMany = [books: Book] String name } class Book { String title } In this case we have a unidirectional one-to-many.

Inheritance or Service for common Domain methods?

可紊 提交于 2019-12-04 19:59:06
I have some methods that are common across a few of my domain classes. I want to reduce the amount of replicated code and two solutions came to mind: 1) Put the common methods in a baseDomain class and inherit the methods from it in my domains 2) Put the common methods in a commonDomainMethodService which I can import into my domains I am thinking I should leave inheritance alone unless the domains share common properties, but I'm not sure. Is one of these methods more beneficial than the other? Is one more in line with Grails best practices? For example a method that compares two domain

dateCreated, lastUpdated fields in Grails 2.0

与世无争的帅哥 提交于 2019-12-04 17:41:47
问题 I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic dateCreated and lastUpdated fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error: | Running Grails application | Error 2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter - ERROR: null value in column "date_created" violates not-null constraint | Error 2012-01-29 22

belongsTo multiple Domain

眉间皱痕 提交于 2019-12-04 16:31:36
I have 4 classes, incidents,problems, requests and another is Attachment. Every domain look like......... Class Incidents { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Problems { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Requests { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Attachment { // other fields static belongsTo= [ incident: Incidents, problem: Problems, requests: Requests ]