gorm

How do you bulk delete records in Grails/GORM?

夙愿已清 提交于 2019-12-03 02:26:26
I have a table which has records that need to be periodically cleared according to a set of criteria. I was expecting that I could use the criteria builder to just delete the records, but that fails because there is no delete method on criteria... def c = Agency.createCriteria() c.delete { eq("agency", "XXX") } So I thought maybe I first query for the set and then delete that... def c = Agency.createCriteria() def deletions = c { eq("agency", "XXX") } deletions.delete This also fails for the same reason, different object. So what is the right way to do this? It seems excessive (perverse) that

Why do I get a “Null value was assigned to a property of primitive type setter of” error message when using HibernateCriteriaBuilder in Grails

◇◆丶佛笑我妖孽 提交于 2019-12-03 02:06:54
问题 I get the following error when using a primitive attribute in my grails domain object: Null value was assigned to a property of primitive type setter of MyDomain.myAttribute org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of MyDomain.myAttribute at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1077) 回答1: According to this SO thread, the solution is to use the non-primitive wrapper types; e.g., Integer

Difference between findAll, getAll and list in Grails

馋奶兔 提交于 2019-12-03 01:28:51
问题 With Grails there are several ways to do the same thing. Finds all of domain class instances: Book.findAll() Book.getAll() Book.list() Retrieves an instance of the domain class for the specified id: Book.findById(1) Book.get(1) When do you use each one? Are there significant differences in performance? 回答1: getAll is an enhanced version of get that takes multiple ids and returns a List of instances. The list size will be the same as the number of provided ids; any misses will result in a null

Grails - mapping a many-to-many parents/children relation to a single join table

痴心易碎 提交于 2019-12-03 00:45:22
My question is based on the following (simplified) Grails domain class class Dimension { String name static hasMany = [ children: Dimension, parents: Dimension ] } Is there a way to map the many-to-many parents/children relationship to a single join table? As far as I know, the only way to do that is to create another domain class that represents a parent-child relationship. class DimensionDependency { Dimension parent Dimension child static belongsTo = Dimension } class Dimension { static hasMany = [parentDependencies: DimensionDependency] static mappedBy = [parentDependencies: 'child']

Why do I get a “Null value was assigned to a property of primitive type setter of” error message when using HibernateCriteriaBuilder in Grails

六月ゝ 毕业季﹏ 提交于 2019-12-02 16:03:10
I get the following error when using a primitive attribute in my grails domain object: Null value was assigned to a property of primitive type setter of MyDomain.myAttribute org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of MyDomain.myAttribute at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1077) Peter According to this SO thread , the solution is to use the non-primitive wrapper types; e.g., Integer instead of int . A null value cannot be assigned to a primitive type, like int, long, boolean, etc. If the

Grails: changing dataSource url at runtime to achieve multi tenant database separation

一笑奈何 提交于 2019-12-02 14:48:17
问题 I'm building a multi tenant application with Grails and I want to keep separate databases. I need to change the url dynamically at runtime to point GORM to different database. I have a front-end acting as a balancer distributing requests to a cluster of backend hosts. Each backend host runs a Grails 2.3.5 instance and a mysql-server with several databases (one per tenant). I would like to change dataSource dynamically so that GORM can access domain entities on the right database. Any ideas ?

Grails select domain objects based on an enum value in an enum list property

落爺英雄遲暮 提交于 2019-12-02 13:40:02
问题 I'm having trouble selecting items from a list of domain objects based on a value in an enum list. My domain object looks like this: class Truck { static hasMany = [ makes: Make ] } where a Make looks like this: enum Make { KENWORTH, MACK, VOLVO } I'm not really sure how do something like Truck.findByMake(Make.MACK) to give me all of the Trucks that have this Make in their list of Makes. That call gives me this error: No property found for name [make] for class [class Truck] Any ideas? Grails

Common beforeInsert and beforeUpdate methods from Mixin for common domain columns

对着背影说爱祢 提交于 2019-12-02 13:14:42
问题 Most of the domain objects our company uses will have some common properties. These represent the user that created the object, the user that last updated the object, and the program they used to do it. In the interest of DRYing out my domain classes, I want to find some way to add the same beforeInsert and beforeUpdate logic to all domain classes that have these columns without interfering with those that don't. How I'd like to do it is using a Mixin with its own beforeInsert and

Grails 3.3.0 with PostgreSQL 10.1 gives column this_.id does not exist error

时光怂恿深爱的人放手 提交于 2019-12-02 12:11:33
问题 I have to make a Grails 3.3.0 web interface for my internship with PostgreSQL version 10.1 as database and spring-security-core version 3.2.0. I used version 42.1.4 as a JDBC driver for PostgreSQL. I've installed PostgreSQL on my Linux laptop and created the webInterfaceDev database with the user postgres. However, every time I want to start the project I get an error that the column this_.id does not exist. This is the error that I get: 2017-11-16 14:42:21.464 ERROR --- [ main] o.h.engine

equivalent of InheritanceType.TABLE_PER_CLASS in grails?

微笑、不失礼 提交于 2019-12-02 11:17:47
I want to create 3 separate tables for 3 domain classes: A, B extends A, C extends B But I want their tables to be NOT connected to each other. In hibernate, I would use InheritanceType.TABLE_PER_CLASS, in grails, what would be the equivalent? Try to use tablePerHierarchy false class Payment { Integer amount static mapping = { tablePerHierarchy false } } class CreditCardPayment extends Payment { String cardNumber } See more : http://grails.org/doc/latest/guide/single.html#5.5.2.3%20Inheritance%20Strategies Something I was trying to also achieve and yes it is possible with grails, it is a case