gorm

Grails Transactions and the Session

耗尽温柔 提交于 2019-12-06 07:56:30
Imagine you have the following controller in a Grails 2.5.5 application: def index() { bookService.method() Book bako = Book.findById(4) System.out.println(bako.title); } And inside the bookService (with Grails default transaction management) you have the following method: class BookService def method() { Book bako = Book.findById(4) System.out.println(bako.title); // MANUAL UPDATE OF DB HAPPENS HERE Book bako = Book.findById(4) System.out.println(bako.title); } } And that your db does have a Book with id 4 called "The Lord of The Rings". If you then set breakpoints on all System.out.println()

How to set formula in grails domain class?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:06:53
I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i.e. can not resolve property 'ddmmyy' of 'myClass'. MyCriteria is: Date myDate = Calender.instance.time

How to encrypt/decrypt columns in a Grails domain class?

只谈情不闲聊 提交于 2019-12-06 07:01:58
问题 As i want to introduce some data security i was wondering if it is possible to encrypt/decrypt specific columns in a Grails domain class and if so what the easiest way is to achieve such a thing? Let say i have a User class and want to encrypt ssn number or bankaccount number so these are not stored as plain text in the DB.. what would be the best approach? 回答1: I created the jasypt encryption plugin for doing exactly this. Docs are on the linked bitbucket wiki and there's also slides from a

eager-loading queries with GORM/Hibernate

流过昼夜 提交于 2019-12-06 06:27:10
问题 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

Grails, GORM, relationship. Optional child records

半世苍凉 提交于 2019-12-06 06:11:39
For example, I've parent class Cafee: class Cafee { String name static hasMany = [ admin: Person ] } and a child class Person: class Person { String name static belongsTo = [cafee: Cafee] } I've done some records to Cafee using: def user = new Person(name: "Andrew") def a = new Cafee(name: "Tarelka") .addToAdmin(user) .save() Adding child to parent works fine, but when I trying to create Person-instance separately, for example: def visitor = new Person(username: 'testerUser', password:'password', firstName:'Иван', lastName:'Иванов', email:'ivanov@gmail.com', isAdminCafee: false) visitor.save

List of Strings in a Grails domain class

瘦欲@ 提交于 2019-12-06 05:59:16
I am trying to have a List of String that works in MySql in a Grails domain class. I have tried the following: class Catalogue { List books String book static hasMany = [books: book] } and class Catalogue { List books } and class Catalogue { String[] books } and class Catalogue { ArrayList<String> books = new ArrayList<String>() } The last three compiles but the entry is not present in MySQL. There is no table, or column to represent this data in MySQL and I have tried populating the array with data. Still nothing. Any ideas? user190117 You can achieve this by using hasMany . Furthermore you

Using traits for horizontal domain class reuse in Grails, a good idea?

痴心易碎 提交于 2019-12-06 05:49:13
So I want to create 3 plugins which include domain classes and a restful service, and who each build on top of each other. Conceptually, they would "inherit" the base model this way: Record > Person > User However I have Read From The Friendly Manual that inheritance may cause some performance issues. Then it crossed my mind that since Groovy has horizontal reuse capabilities (i.e. traits), I may very well just define everything in the trait and then implement the trait in the domain class. Composing domain classes is not an option for me because of the renaming of the fields, and well, the

How to convert javassist instance into instance of a specific domain

北战南征 提交于 2019-12-06 05:28:55
I would like to intersect two lists of instances of a specific domain class using grails 1.3.7. The problem is, that the instances of one list are created by javasisst so that the result of the intersection is always an empty list. Here are my domains: class User { ... static hasMany = [foos : Foo] ... } class Foo { ... static hasMany = [bars : Bar] ... } class Bar { ... static hasMany = [localizedTitles : LocalizedTitle] ... } I get the list of all Bar instances of the user like this: def allBarsOfUser = userInstance.foos.bars.flatten() And try to intersect with another list of Bar instances:

Renaming composite foreign keys in GORM

非 Y 不嫁゛ 提交于 2019-12-06 05:24:54
I have the following classes: class Catalog { static mapping = { id composite:['name', 'manufacturer'] columns { name column:'cat_name' manufacturer column:'manuf_id' } } String name Manufacturer manufacturer } class Order { static mapping = { columns { // How to rename foreign keys as cat_name, manuf_id? } } Catalog catalog // creates catalog_name, catalog_manufacturer_name } Presently, an Order table is generated with the attributes catalog_name and catalog_manufacturer_name (which reference the composite primary keys of the Catalog table). I need to rename these generated columns to cat

Grails 2.4.2 - Dynamically referencing default datasource

ⅰ亾dé卋堺 提交于 2019-12-06 05:19:18
问题 This question has been partly answered here but there is still an issue with referencing the default datasource dynamically. I'm working on an internal application that allows developers to modify configuration settings for one of our multi-tenant applications and push those settings from dev to testing, staging and production. Each one of these will have their own datasource, and the Grails app will be installed on each developer's computer. The local datasource will be the default one, and