gorm

Case-insensitive unique constraint in Grails

萝らか妹 提交于 2019-12-22 06:48:37
问题 How can I basically carry out a unique constraint on a string data-type field. class User{ String username String Email static hasMany = [roles:Roles] static constraints = { Email(email:true) username(unique:true) } } Is there any simple way to implement username(unique: true) Or must I manually check the database using methods like .findByNameLike ? The username should be unique, but the uniqueness is should be case-insensitive. 回答1: So, if you want to have unique and case insensitive

How do I get Grails to map my String field to a Clob?

落花浮王杯 提交于 2019-12-22 05:14:28
问题 My domain class looks like this: package com.initech.tps class Foo { String stuff static mapping = { // mapping to a legacy table as opposed to letting Grails create it table name: 'FOO', schema: 'TPS' id generator: 'sequence', params: [sequence: 'MY_SEQ'], column: 'FOO_ID', sqlType: 'integer' foo column: 'STUFF' } static constraints = { stuff(nullable: true, maxSize: 40000) } } I was under the impression Grails would figure out to use a CLOB instead of a VARCHAR based on my passing in a big

How do I get Grails to map my String field to a Clob?

时光毁灭记忆、已成空白 提交于 2019-12-22 05:14:23
问题 My domain class looks like this: package com.initech.tps class Foo { String stuff static mapping = { // mapping to a legacy table as opposed to letting Grails create it table name: 'FOO', schema: 'TPS' id generator: 'sequence', params: [sequence: 'MY_SEQ'], column: 'FOO_ID', sqlType: 'integer' foo column: 'STUFF' } static constraints = { stuff(nullable: true, maxSize: 40000) } } I was under the impression Grails would figure out to use a CLOB instead of a VARCHAR based on my passing in a big

GORM in Grails and StaleObjectStateException

白昼怎懂夜的黑 提交于 2019-12-22 04:43:35
问题 I'm writing a small Grails app, and I keep on getting StaleObjectStateException:s for about 1/10:th of the calls to "createfoo" when running the following rather simple code. Most probably I'm missing out on the best way to use GORM. This is the code: def viewfoo = { session.user.refresh() // ... } def createfoo = { session.user.refresh() var user = session.user if (param["name"]) { var newFoo = new Foo() newFoo.name = param["name"] if (newFoo.validate()) { newFoo.save() if (user.validate())

Why is uniquely constrained field failing on update, in Grails

陌路散爱 提交于 2019-12-22 04:37:08
问题 When i have a custom identity attribute mapped in a domain class, why does hibernate check for unique constraint? When i update an object, the validation fails despite the fact that the posted field value is the same as that stored in DB! This occurs, even if I make no change to the form (ensuring dirty: false and no property binding errors). I have a Grails domain class like below: class User { Long profileId String email String username String password String title String firstname String

Grails: How to query objects in many to many mapping?

北慕城南 提交于 2019-12-22 04:06:14
问题 Hello I have the follwing domain classes. class Student { int age static hasMany = [courses:Course] } class Course { String name static hasMany = [students:Student] } I want to find the Students taking Course (with id 1), with age 7. Could I do that with dynamic finder or criteria builder or HQL? I do not want to do following as it load all students so inefficient: def course = Course.get(1); course.students.findAll{ it.age == 7 } 回答1: def studs = Student.withCriteria { eq('age', 7) courses {

Grails domain-classes mapping in one-to-one relation

情到浓时终转凉″ 提交于 2019-12-22 00:18:39
问题 I have ready database table schema and I need use it in my Grails app. My tables in PostgreSQL: CREATE TABLE "user" ( id serial NOT NULL, login character varying(32) NOT NULL, password character varying(32) NOT NULL, email character varying(255) NOT NULL, date_created time with time zone NOT NULL DEFAULT now(), last_updated time with time zone NOT NULL DEFAULT now(), is_banned boolean DEFAULT false, CONSTRAINT "PK_user_id" PRIMARY KEY (id), CONSTRAINT "UN_user_email" UNIQUE (email),

Grails: One Database and more than one application

浪子不回头ぞ 提交于 2019-12-21 20:24:40
问题 I am having Grails GORM based application.One web service and one website both are running on different port and sharing common database and tables. What i have done is created domain class for both application which are having same fields and domain class name.For example Registration table having userName and password fields.One can register through web service and also from website. My current applications is working fine...but is it a feasible solution..? Thanks, Viral 回答1: You could run

Grails - Sort by two fields in a query

时光毁灭记忆、已成空白 提交于 2019-12-21 20:03:16
问题 I Have Such a domain class in my project: class Log { Integer entityId Integer tableId Date logDt } I would like to select all the records by a certain tableId, and sort them by entityId and logDt desc. Sorting by one filed works fine: Log.findAllByTableId(tableID, [sort: 'entityId', order: 'desc']) but when I try to sort by both fields: Log.findAllByTableId(tableID, [sort: 'entityId,logDt', order: 'desc']) I get an error that there is no such field 'entityId,logDt' at this table. What is the

Overriding event closure on Grails GORM domain class for unit testing

泪湿孤枕 提交于 2019-12-21 17:56:47
问题 I'm working on a fresh Grails project and recently noticed the default convention in the Spring Security Core generated User class now auto-encodes the password via a beforeInsert/Update event. That's a nice, clean, DRY way of doing the encode, and also makes it impossible to forget to do so. However, now when trying to write up some unit tests which make use of said User class, I find I either have to mock out the springSecurityService (due to the encode), or more preferably (and cleanly), I