gorm

An issue while creating multiple unique columns with GORM

冷暖自知 提交于 2019-12-12 05:26:20
问题 I have this Grails domain class: class MyClass { static auditable = true; String description; Boolean isActive=true; Date deletedAt; static constraints = { description size: 1..250, blank: false, unique:['deletedAt', 'isActive'], index:'myclass_idx' deletedAt nullable: true, index:'myclass_idx' isActive index:'myclass_idx' } } What I expect it to do is to create a constraint which won't allow duplicate records like these: id| description | is_active | deleted_at 1 | desc1 | true | (null) 2 |

HasOne and HasMany of the same domain class and cascade save

徘徊边缘 提交于 2019-12-12 05:09:58
问题 I have 2 domain classes; the forst of them represents an email address, with the name of the user and the email address itself. The other class represents an email message, with the subject, the sender (one email address) and the recipients (a list of email addresses): class EmailMessage { static hasMany = [ to: EmailAddress ] EmailAddress from String subject } class EmailAddress { String name String address } But this code doesn't work as I expect: EmailMessage msg = new EmailMessage() msg

Foreign key (FK_ must have same number of columns as the referenced primary key

可紊 提交于 2019-12-12 05:09:33
问题 I'm working with a legacy database where Table A consist of 3 composite keys and Table B consist of 2 composite keys which are the same as two of the composite keys from Table A OnesolPeNames class OnesolPeNames implements Serializable { static mapping = { table "ONESOL_pe_names" id composite: ["division", "peid"] columns{ division column: 'division', length: 8, sqlType: "char" peid column: 'pe_id', length: 12, sqlType: "char" peNameU column: 'pe_name_u', length: 50, sqlType: "char" } }

One-to-Many With Composite Keys and Different Column Names in Grails

谁都会走 提交于 2019-12-12 04:37:05
问题 This is a syntax question. I want a one-to-many relationship between Foo -> Bar (simplified here): class Foo { String fooPK1, fooPK2 static mapping = { id composite: ["fooPK1", "fooPK2"] } static hasMany = [bars: Bar] } class Bar { String fooPK1, dumbNameForFooPK2, barPK1, barPK2 Foo myFoo static mapping = { id composite: ["barPK1", "barPK2"] columns { myFoo[:] { column name: "FOO_PK_1" column name: "?????????????" } } } } In this case, obviously Foo.fooPK1 maps to Bar.fooPK1, but i need Foo

NumberFormatException For input string when try to do a date search in grails

对着背影说爱祢 提交于 2019-12-12 04:29:24
问题 I get from the gsp view a string with the date and time: def name = params.name def time = params.minutes def date = params.datapicker Now, I want to do a search in my domain by date and name. So, I join the date and time and do the search: def dataSearch = date + " " + time MyDomain result= MyDomain.findByNameAndDateCreatedGreaterThan(name, dataSearch) But, I'm getting this error: 2016-05-26 09:56:44,488 [http-bio-8090-exec-3] ERROR errors.GrailsExceptionResolver - NumberFormatException

join query on one-to-one Grails domain using GORM with parameters

二次信任 提交于 2019-12-12 03:44:03
问题 I have a two Grails domain class, let say: class Hero { String name Float level Familiar familiar } class Familiar { String name Integer raceId } Now, what I want is to retrieve all Hero having Familiar with the name similar to a given String , for example : "hachiko" . To do that using SQL , all I need is to perform a query similar to this: SELECT h.name, h.level FROM HERO h JOIN FAMILIAR f ON h.id = f.ownerId WHERE f.name LIKE '%hachiko%' But how can I do that on Grails ? This is my code:

DB2 Before Update Trigger Behavior

你。 提交于 2019-12-12 03:43:03
问题 Wondering if someone can help me understand how a DB2 before insert trigger behaves. I have a Grails app that inserts rows to a DB2 database. The table in question has a before insert trigger that updates the date and user for the update: CREATE TRIGGER WTESTP.SCSMA11I NO CASCADE BEFORE INSERT ON WTESTP.SCSMA01T REFERENCING NEW AS NEWROW FOR EACH ROW MODE DB2SQL BEGIN ATOMIC SET NEWROW.LST_UPDT_TMSP = CURRENT_TIMESTAMP ; SET NEWROW.USER_ID = RTRIM ( USER ) ; END ; In my Grails application I

Adapt field to store to database

三世轮回 提交于 2019-12-12 03:39:35
问题 Say I have a field content that is a json. I would like to store it in database so that my domain class keeps only the 1 field only. (It's more of a brain task ;-) class MyDomain{ def content static constraints = { content nullable: false, blank: false, sqlType: "text" // adapter from JSON to String?? } def beforeInsert(){ content = content.toString() } def beforeUpdate(){ content = content.toString() } def afterInsert(){ content = JSON.parse(content) as JSON } def afterUpdate(){ content =

can't get cascade save nor delete on embedded class ref to work

痴心易碎 提交于 2019-12-12 02:18:47
问题 i've created two simple grails V3 domain classes where location is embedded attribute type in parent Venue like this import java.time.LocalDate class Venue { String name LocalDate dateCreated LocalDate lastVisited LocalDate lastUpdated GeoAddress location static hasOne = [location:GeoAddress] static embedded =['location'] static constraints = { lastVisited nullable:true location nullable:true } static mapping = { location cascade: "all-delete-orphan", lazy:false //eager fetch strategy } }

grails: testing 'sort' mapping in a domain class

青春壹個敷衍的年華 提交于 2019-12-12 01:59:23
问题 Given the example from grails doc: class Airport { … static hasMany = [flights: Flight] static mapping = { flights sort: 'number', order: 'desc' } } How can one test sorting? 回答1: As stated in the docs, it does not work like written. You have to add static belongsTo = [airport:Airport] to Flight. Without belongsTo you get the following error: Default sort for associations [Airport->flights] are not supported with unidirectional one to many relationships. With belongsTo the test could look