gorm

Grails Domain Class : hasOne, hasMany without belongsTo

拥有回忆 提交于 2020-01-02 03:30:09
问题 I am new to Grails. Can I use "hasOne" or "hasMany" without using "belongsTo" to another domain-class? Thanks in advance. 回答1: 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 =

GORM default Date format when sending date to Grails

橙三吉。 提交于 2020-01-01 12:34:07
问题 I am sending a JSON PUT request to Grails. In the JSON object, I have a date string. I have searched and experimented, but I cannot determine the default date string format that GORM wants to parse the date string. In all my attempts I get the following error: java.lang.IllegalArgumentException: Could not parse date: Unparseable date I just want to know the default format GORM expects and I will happily format the date string in that format before sending it to the server. 回答1: I suppose you

Grails: map mysql field of type enum to domain class

橙三吉。 提交于 2020-01-01 12:09:10
问题 How can I map a mysql field of type enum to a grails domain class? I'm using an existing (legacy) mySQL database with grails v.2.0.3. I'm getting an error for Wrong column type: failed; nested exception is org.hibernate.HibernateException: Wrong column type in facilities.ost_fac_syslog for column log_type. Found: enum, expected: varchar(255) The SQL field is defined as: mysql> describe ost_fac_syslog; +------------+---------------------------------+------+-----+-------------------- | Field |

Dynamically creating a query based on params being passed to a controller

六眼飞鱼酱① 提交于 2020-01-01 11:42:05
问题 In my task management application, users should be able to filter tasks based on : assignedTo , priority , status and/or dueDate I am not sure on how to create a dynamic query in that it will build a query based on the available parameters. For example : If I have a URL such as : task/index?assignedTo=1&status=2 I can build a query based on only these two parameters. The method I am used to is the Task.findAllByAssignedToAndStatus( User.get(params.assignedTo), TaskStatus.get(params.status) )

Dynamically creating a query based on params being passed to a controller

谁说胖子不能爱 提交于 2020-01-01 11:41:47
问题 In my task management application, users should be able to filter tasks based on : assignedTo , priority , status and/or dueDate I am not sure on how to create a dynamic query in that it will build a query based on the available parameters. For example : If I have a URL such as : task/index?assignedTo=1&status=2 I can build a query based on only these two parameters. The method I am used to is the Task.findAllByAssignedToAndStatus( User.get(params.assignedTo), TaskStatus.get(params.status) )

or in namedQueries in Grails 2.3.8: AbstractMethodError

人盡茶涼 提交于 2019-12-31 05:48:10
问题 After upgrading from Grails 2.2.4 to 2.3.8 I'm getting java.lang.AbstractMethodError: grails.orm.HibernateCriteriaBuilder.or(Lgroovy/lang/Closure;)Lorg/grails/datastore/mapping/query/api/Criteria; in a query class Trip { TripParticipant driver, passenger static namedQueries = { byParticipant { UserAccount ua, name = null -> or { for( n in ( name ? [ name ] : [ 'driver', 'passenger' ] ) ) { eq "${n}.account", ua } } } } } class TripParticipant { UserAccount account boolean rated = false } any

How Grails gorm will insert table per concrete class where each concrete class inherits an abstract class

白昼怎懂夜的黑 提交于 2019-12-30 11:31:51
问题 Hi all following is the situation I have an abstract class AbstractProfile and one concrete class GoogleProfile abstract class AbstractProfile { ..... } class GoogleProfile extends AbstractProfile { ...... } I am using grails but gorm is not inserting table for google profile current gorm is inserting table for only AbstractProfile class please help Thanks in advance 回答1: I did some digging and found out that starting on grails 2.3 you have the following mapping option: tablePerConcreteClass

Grails / GORM criteria query with hasmany String

我只是一个虾纸丫 提交于 2019-12-30 08:09:10
问题 I have a domain object (Cat) like this: class Cat { String name static hasMany = [ nicknames: String ] } (A cat has a name, and also has many nicknames (which are Strings)) And I am trying to query all the cats with certain nicknames. I've tried this: PagedResultList getCatsByNickname(String nickname, Map params) { PagedResultList results = Cat.createCriteria().list(params) { 'ilike'('nicknames','%'+nickname+'%') } return results } But it never returns any results. (If I change the query to

Changing primary key id to String type in Grails

会有一股神秘感。 提交于 2019-12-30 02:02:06
问题 My Grails 2.0 app has a User domain object defined: class User { static mapping = { table "dt_user" columns { id column:'user_id', generator:'assigned', type:'string' } } When I try to save a new User in my BootStrap file like so: def user = new User(id: "smith").save(failOnError:true) I get the following error: | Error 2012-01-13 10:09:42,659 [main] ERROR property.BasicPropertyAccessor - IllegalArgumentException in class: User, setter method of property: id | Error 2012-01-13 10:09:42,660

Grails: setting transient fields in the map constructor

江枫思渺然 提交于 2019-12-29 08:16:27
问题 I'm trying to persist Maps of properties as single JSON-encoded columns, as shown in this question. The problem I'm having is that apparently transient properties cannot be set in the default map constructor . Given any transient field: class Test { //... String foo static transients = ['foo'] } It seems that the map constructor (which Grails overrides in various ways) simply discards transient fields: groovy:000> t = new Test(foo:'bar') ===> Test : (unsaved) groovy:000> t.foo ===> null While