gorm

Grails Transactions and the Session

懵懂的女人 提交于 2019-12-22 16:44:55
问题 Imagine you have the following controller in a Grails 2.5.5 application: def index() { bookService.method() Book bako = Book.findById(4) System.out.println(bako.title); } And inside the bookService (with Grails default transaction management) you have the following method: class BookService def method() { Book bako = Book.findById(4) System.out.println(bako.title); // MANUAL UPDATE OF DB HAPPENS HERE Book bako = Book.findById(4) System.out.println(bako.title); } } And that your db does have a

Grails Transactions and the Session

青春壹個敷衍的年華 提交于 2019-12-22 16:44:15
问题 Imagine you have the following controller in a Grails 2.5.5 application: def index() { bookService.method() Book bako = Book.findById(4) System.out.println(bako.title); } And inside the bookService (with Grails default transaction management) you have the following method: class BookService def method() { Book bako = Book.findById(4) System.out.println(bako.title); // MANUAL UPDATE OF DB HAPPENS HERE Book bako = Book.findById(4) System.out.println(bako.title); } } And that your db does have a

Grails Transactions and the Session

纵饮孤独 提交于 2019-12-22 16:43:08
问题 Imagine you have the following controller in a Grails 2.5.5 application: def index() { bookService.method() Book bako = Book.findById(4) System.out.println(bako.title); } And inside the bookService (with Grails default transaction management) you have the following method: class BookService def method() { Book bako = Book.findById(4) System.out.println(bako.title); // MANUAL UPDATE OF DB HAPPENS HERE Book bako = Book.findById(4) System.out.println(bako.title); } } And that your db does have a

How to set formula in grails domain class?

烈酒焚心 提交于 2019-12-22 13:04:50
问题 I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i

How to set formula in grails domain class?

帅比萌擦擦* 提交于 2019-12-22 13:03:08
问题 I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i

How to set formula in grails domain class?

心不动则不痛 提交于 2019-12-22 13:03:06
问题 I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i

Changing the data type of the [hasMany:] reference to a list?

南笙酒味 提交于 2019-12-22 12:54:05
问题 Is there a way to change the data type of the static hasMany = [myList: Stuff] definition in grails? I tried List<Stuff> myList hasMany = [myList : Stuff] but my existing tests started throwing Stuff._MyContainer_mylistBackref; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value which indicates the two aren't equivalent in terms of how they're being handled. What am I doing wrong here? 回答1: As described in section 5.2.4 of the

gorm one to many search

时光毁灭记忆、已成空白 提交于 2019-12-22 11:37:14
问题 Have the following problem: I have Bookmaker and Users domain classes. And one Bookmaker has many Users. class Bookmaker { ... static hasMany = [users: User ...] ... } And User domain class doesn't contain reference to Bookmaker. My goal is to create method that will return Bookmaker that owns particular User. It looks like: def lookupBookmaker() { User user = User.get(springSecurityService.principal.id) def query = Bookmaker.where { users.contains(user) } Bookmaker bookmaker = query.find()

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

。_饼干妹妹 提交于 2019-12-22 09:22:43
问题 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();

How can I use embedded GORM classes in Grails?

元气小坏坏 提交于 2019-12-22 08:57:50
问题 Following the GORM docs I tried to use the following domain class with Grails 2.2.1: package grailscompositiontest class ScafPerson { String name ScafAddress homeAddress ScafAddress workAddress static constraints = { name(nullable: false, blank: false) } static embedded = ['homeAddress', 'workAddress'] } class ScafAddress { String number String code } The controller just uses scaffolding: package grailscompositiontest class ScafPersonController { static scaffold = true } Unfortunately this