gorm

dateCreated, lastUpdated fields in Grails 2.0

落花浮王杯 提交于 2019-12-03 12:17:14
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:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener - Could not synchronize database

How do I clear and replace a collection in a one-to-many relationship in Grails/Groovy

醉酒当歌 提交于 2019-12-03 11:45:55
This question is in two parts, first part is about clearing a list and second part is about assigning an owner to an object. I have a one-to-many relationship between two domain objects in my model in Grails. The relationship looks like this... class Person { static hasMany = [authorities: Role, locations: Location] } class Location { static belongsTo = Person } In my app the locations list on Person gets completely refreshed and replaced with a new list on a user action. What's more I get the list of Location objects independent of the associated Person . I resolve which person to apply them

withCriteria two level deep association eager fetch grails

两盒软妹~` 提交于 2019-12-03 11:42:38
问题 I'd like to eager load a structure, two levels deep in an association chain. Something along the lines of: class TopLevel { String name LevelOne levelOne } class LevelOne { String name LevelTwo levelTwo } class LevelTwo { String name } I'd like to load the entire structure. Searching around I found this example, but it didn't work. The "println" generated a query to the LevelTwo table. def result = TopLevel.withCriteria { eq('name', 'test') fetchMode "levelOne", FetchMode.JOIN levelOne {

GORM domain class properties default values

前提是你 提交于 2019-12-03 11:27:45
Maybe a silly question but where/how should I define default values for GORM domain class properties? For example when I'm creating a new Company object instance I want default value for property country to be "USA". I guess I could do it in create controller but it looks kinda dirty. Something like: def create = { def companyInstance = new Company() companyInstance.properties = params companyInstance.accepted = "USA" ... Put it in the domain class itself class Company { String country = "USA" } 来源: https://stackoverflow.com/questions/8256627/gorm-domain-class-properties-default-values

grails hasOne vs direct member variable

我是研究僧i 提交于 2019-12-03 11:08:47
问题 Let's say I have a grails domain class that looks like class Person { Address address } I could also declare it as class Person { static hasOne = [address:Address] } The second way would move the foreign key to the Address table rather than the person table. What are the practical benefits (or disadvantages) of doing this one way vs the other? As far as I understand, they will both use foreign keys, it's just a matter of where the foreign key lives. 回答1: If the foreign key exists on the

How do you bulk delete records in Grails/GORM?

◇◆丶佛笑我妖孽 提交于 2019-12-03 10:56:47
问题 I have a table which has records that need to be periodically cleared according to a set of criteria. I was expecting that I could use the criteria builder to just delete the records, but that fails because there is no delete method on criteria... def c = Agency.createCriteria() c.delete { eq("agency", "XXX") } So I thought maybe I first query for the set and then delete that... def c = Agency.createCriteria() def deletions = c { eq("agency", "XXX") } deletions.delete This also fails for the

Grails Hibernate4 upgrade errors on getGeneratedKeys()

隐身守侯 提交于 2019-12-03 10:36:28
I'm upgrading to the Hibernate4:4.3.5.3 plugin for Grails 2.3.9 . However, I'm getting an error: getGeneratedKeys() support is not enabled I haven't been able to find any configuration details on how to enable this. I just found that you can configure it under DataSource.groovy in the hibernate{...} block hibernate{ jdbc.use_get_generated_keys = true } 来源: https://stackoverflow.com/questions/24050291/grails-hibernate4-upgrade-errors-on-getgeneratedkeys

Grails/GORM “in” criteria

倾然丶 夕夏残阳落幕 提交于 2019-12-03 10:03:34
Is it possible to do an "in" criteria using the GORM criteria. I'm looking for the equivalent of the following SQL select * from Person where age in (20,21,22); If it was possible I guess the syntax would be something like: def results = Person.withCriteria { in "age", [20, 21, 22] } The Grails createCriteria documentation includes an example of using the in clause: 'in'("holderAge",[18..65]) or not{'in'("holderAge",[18..65])} The documentation includes this note: Note: 'in' is a groovy reserve word, so it must be escaped by quotes. Yep, you have it almost exactly right. Just change in to 'in'

Using Postgresql with Grails : Missing sequence or table: hibernate_sequence

亡梦爱人 提交于 2019-12-03 09:00:44
I'm having trouble with Grails 2.0 and Postgresql 9.1 I'm trying to map an existing database, with sequential ids. However, even without creating any class in the domain, I'm having the error : Compiling 1 source files..... | Running Grails application | Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property

Grails: No signature of method findAll() is applicable for argument types: String, ArrayList

久未见 提交于 2019-12-03 08:59:36
I'm new to grails and receive the following error: No signature of method: Something.findAll() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [from Something AS s WHERE s.some_number LIKE ?, [%asdf%]]" The error occurs when I run test-app . It occurs in the following place: SomethingVO[] findBySomeNumber(String searchString) { searchString = "%"+searchString+"%" return Something.findAll("from Something AS s WHERE s.some_number LIKE ?",[searchString]).collect { new SomethingVO(it); } } The class Something is a domain object: package some.project.domain class