gorm

Configuring Postgres in Grails

試著忘記壹切 提交于 2019-12-06 04:48:19
I have an application in migrating to MySQL and PostgreSQL and I both have different behaviors in the allocation of data. By analyzing the database created in Postgres, I realized that the numbering of ID's created in each table are not being reset in change for another table. For example, it was set in the registers 3 'Table1' and counting the ID 1 to 3. When inserted into an object of another class in another table, the ID should be started for that table, but it follows the sequence of previous and when the object is persisted in 'table2' instead his first start with the ID continues to

lazy column loading in Grails domain class

有些话、适合烂在心里 提交于 2019-12-06 04:21:47
I have a domain class like this: class Document { String mime; String name; byte[] content; static mapping = { content lazy:true; } } and I'd like to enable lazy loading to the "content" column, because the application does some stuff without the need of access to this column. But the lazy:true option didn't work... any idea or workaround? What do you mean by the application does some stuff? and what are you trying to establish? FYI. eager and lazy loading usually has to do with relations, grails by default has lazy loading enabled. e.g." Class Book{ static belongsTo = Author String Name

Grails - use java domain classes to create grails domain classes using GORM

↘锁芯ラ 提交于 2019-12-06 04:08:49
问题 Found some partial answers to the below scenario but require further clarification. Have the following situation: domain classes written in java the domain classes are not mapped to a DB through hibernate the java classes are used by a java server which simply performs intensive computations before returning result to client as a serialized java class What I would like to do: create a grails application which could do the following: use the java domain classes as grails domain classes have

distinct result in Hibernate Query in grails with pagination using association

♀尐吖头ヾ 提交于 2019-12-06 04:06:16
问题 I have three class interlinked with each other. Initially I build query without pagination and all search results were fine. But now I need pagination and don't want to disturb my initial query pattern. Is there any way I could get distinct results. Class Department{ int id; String name; static hasMany = [courses:Courses] } Class Courses{ String courseName; String courseCode; static hasMany = [student:Student] static belongsTo = [department:Department] } Class Student{ String studentName;

Grails GORM query for null hasOne association fails

眉间皱痕 提交于 2019-12-06 03:38:54
问题 I use Grails 2.2.4 (same behaviour in Grails 2.3.11) and have a domain class A that references a domain class B class A { static hasOne = [b: B] static constraints = { b nullable: true } } class B { static belongsTo = [a: A] } I try to find all instances of A that have a B. A.findAllByBIsNotNull()*.b returns a list of Bs and nulls: [null, null, b1, b2, null, ...] How so? Same happens if I use A.withCriteria { isNotNull 'b' }*.b What do I do wrong? UPDATE: I realized that the problem is

Stripping trailing whitespace from char fields in a legacy database with Grails GORM

99封情书 提交于 2019-12-06 03:19:40
问题 What are the possible solutions for stripping the trailing whitespace when mapping char fields in a legacy database? I see the following options: Calling .trim() at the point of use (controller, view, etc) Override property accessors to return .trim() Using a Hibernate UserType to trim the whitespace I'm leaning toward overriding the property accessor so that the domain properties remain consistent throughout the application. 回答1: I had a similar problem and I could not alter the legacy data.

Abstract Classes in GORM Relationships

送分小仙女□ 提交于 2019-12-06 02:46:14
问题 Grails GORM does not persist abstract domain classes to the database, causing a break in polymorphic relationships. For example: abstract class User { String email String password static constraints = { email(blank:false, nullable:false,email:true) password(blank:false, password:true) } static hasMany = [membership:GroupMembership] } class RegularEmployee extends User {} class Manager extends User { Workgroup managedGroup } class Document { String name String description int fileSize String

Grails belongsTo cascade on delete when belongsTo specifies multiple classes?

旧巷老猫 提交于 2019-12-06 02:04:12
class Owner { static hasMany = Dog } class Sitter { static hasMany = Dog } class Dog { static belongsTo = [Owner, Sitter] } My question is: If I create a Dog instance D, a Owner instance O, a Sitter instance S and associate D with both O and S, what happens to O when S gets deleted? Would O still have D? Since it's a cascade-delete, both S and D would get deleted, right? When what happens to O? Would it still have D? I have tested it, it follows the cascade rule: if you delete Owner, Dog will be deleted by cascade, but Sitter will remain. And it's reasonable: Sitter is independent with Owner.

GORM access list index of hasMany association

♀尐吖头ヾ 提交于 2019-12-06 01:50:30
My application has domain classes which have the same logical relation as photo albums and individual photographs. Using a List for the hasMany association should support backwards and forward movement within individual albums, without having to explicitly manage a position field or previous / next pointers. For example: class Album { static hasMany = [photos: Photo] List photos // Generates column `album_idx` in table for Photo. Integer size // Memoized. } class Photo { static belongsTo = [album: Album] static hasOne = [content: PhotoData] // PhotoData has byte[] field for data } class

Sharing environment settings in datasource.groovy

霸气de小男生 提交于 2019-12-06 01:47:35
So we are able to create different environment settings in the datasource.groovy file. And we can put common settings outside the environments node like so dataSource { pooled = false driverClassName = "org.h2.Driver" username = "sa" password = "" } environments { development { dataSource { dbCreate = "create-drop" url = "jdbc:h2:mem:devDb" } } test { dataSource { dbCreate = "update" url = "jdbc:h2:mem:testDb" } } production { dataSource { dbCreate = "update" url = "jdbc:h2:prodDb" } } } But is there a way to so that we can have certain enviroments share some properties while others share a