gorm

How to ensure data integrity when using Table Per Subclass?

痞子三分冷 提交于 2019-12-04 23:13:10
问题 I am using the table per subclass strategy in Grails by setting the tablePerHierarchy property of the static mapping field in my superclass to false. This way, Grails creates one table for my superclass and one additional table for each of my subclasses. However, while the superclass and subclass records share the same ID (primary key), there are no foreign key constraints to keep them consistent, i.e. it is possible to delete the superclass record, leaving the subclass record in an invalid

pessimistic locking in GORM where query

让人想犯罪 __ 提交于 2019-12-04 21:07:08
I'd like to achieve pessimistic lock with GORM's where query. Something like def query = Person.where { firstName == "Bart" } //instead of where.findAll() List personsLocked = where.lockAll() I know, I can achieve that by criteria API: List personsLocked = Person.createCriteria().list { eq('firstName', 'Bart') lock true } Is there a way to achieve this via the "where" query ? lock is not available in the grails.gorm.DetachedCriteria (result of where ) and is only available from the org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder provided by createCriteira or by

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

微笑、不失礼 提交于 2019-12-04 19:51:28
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), CONSTRAINT "UN_user_login" UNIQUE (login) ) CREATE TABLE profile ( "user" integer NOT NULL DEFAULT nextval(

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

心已入冬 提交于 2019-12-04 19:13:25
问题 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

dateCreated, lastUpdated fields in Grails 2.0

与世无争的帅哥 提交于 2019-12-04 17:41:47
问题 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

Grails Hibernate4 upgrade errors on getGeneratedKeys()

余生颓废 提交于 2019-12-04 16:48:48
问题 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. 回答1: 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

belongsTo multiple Domain

眉间皱痕 提交于 2019-12-04 16:31:36
I have 4 classes, incidents,problems, requests and another is Attachment. Every domain look like......... Class Incidents { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Problems { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Requests { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Attachment { // other fields static belongsTo= [ incident: Incidents, problem: Problems, requests: Requests ]

How to optimize this GORM query

寵の児 提交于 2019-12-04 15:12:11
I have a query which makes 2 database queries. I am new to GORM and don't know how to optimize it into 1 query using criteria, or a where clause or something else. I'm using springsecurity as well and have a User class for login security. I have a Profile class with a User object: class Profile { User user } In my controller the session stores the user id. When I want to load the profile to update it my code is currently: def user = User.get(springSecurityService.principal.id) // 1st db query def domainObject = Profile.findByUser(user) // 2nd db query I've tried a few query variations through

eager-loading queries with GORM/Hibernate

懵懂的女人 提交于 2019-12-04 14:33:33
My Grails app has the following domain objects class ProductType { String name static hasMany = [attributes: Attribute] } class Attribute { String name static belongsTo = [productType: ProductType] } My DB has 7 ProductType s and each of those has 3 Attribute s. If I execute the query: def results = ProductType.withCriteria { fetchMode("attributes", org.hibernate.FetchMode.EAGER) } I expect 7 instances of ProductType to be returned, but in fact I get 21 (7 x 3). I understand that if I were to execute an equivalent SQL query to the above, the result set would have 21 rows prod1 | attr1 prod1 |

Using Postgresql with Grails : Missing sequence or table: hibernate_sequence

天大地大妈咪最大 提交于 2019-12-04 14:32:49
问题 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