gorm

Grails: Best approach to dealing with an existing database

倾然丶 夕夏残阳落幕 提交于 2020-01-03 13:57:09
问题 I'm writing a Grails application that will be pulling data from an existing Oracle database. If I were designing this from scratch I could hold all the information in two or three domain models because logically that's how the data should be arranged. However, this is a pre-existing database that has the data I need spread across approximately 25-30 tables. So I am wondering which of the following approaches would be considered best. I don't want to do tons of extra work to take advantage of

Grails: Best approach to dealing with an existing database

故事扮演 提交于 2020-01-03 13:56:28
问题 I'm writing a Grails application that will be pulling data from an existing Oracle database. If I were designing this from scratch I could hold all the information in two or three domain models because logically that's how the data should be arranged. However, this is a pre-existing database that has the data I need spread across approximately 25-30 tables. So I am wondering which of the following approaches would be considered best. I don't want to do tons of extra work to take advantage of

Grails 3.0.1 - how and where to configure grails.gorm.default.mapping

点点圈 提交于 2020-01-03 13:29:32
问题 I had in the old Config.groovy: grails.gorm.default.mapping = { id generator = 'identity' // send only the dirty fields to the database for updating dynamicUpdate = true dynamicInsert = true } So I put this in the additionally application.groovy, but it won't be respected any more. All updates are full, sending all fields to the database, even the not changed ones. I tried to translate this in application.yml: grails: gorm: default: mapping: id generator: "identity" dynamicUpdate: true

How to model stored procedure records in Grails?

懵懂的女人 提交于 2020-01-03 02:25:16
问题 I need to call some stored procedures that return their own kinds of records, that are not directly mapped to tables or views. I have used stored procedures in the past with groovy.sql.Sql and plain (unmodelled) Maps, but for this application I would like to model those records with something akin to domain classes, in order to define data types, data binding, validation, associations to other entities, and so on. What is the best way to do so? Should I model the stored procedure records as

Get a list of all objects grails is planning to magically save

我怕爱的太早我们不能终老 提交于 2020-01-03 01:59:08
问题 If I make a domain object in a controller and don't call .save() , Grails will do it for me automatically at some point. I am creating lots of domain objects without planning to save all of them and getting 'references an unsaved transient instance' exceptions when my service exits. How would I get a list of all objects that Grails will try to save when the controller/service exits so that I could prevent some of them from being saved? 回答1: You're better off retrieving instances that you know

Grails criteria select when hasMany hasn't any elements

空扰寡人 提交于 2020-01-02 23:26:09
问题 I have the classes: class Course{ String name static hasMany = [ studentGrades: StudentGrade ] } class StudentGrade{ String name int grade } How can I make a criteria to get the courses without any student grade? 回答1: You could use the isEmpty criterion method: def c = Course.createCriteria() def results = c.list { isEmpty("studentGrades") } See the docs for further informations. 来源: https://stackoverflow.com/questions/10429023/grails-criteria-select-when-hasmany-hasnt-any-elements

Configuring Postgres in Grails

限于喜欢 提交于 2020-01-02 11:00:08
问题 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

Configuring Postgres in Grails

本小妞迷上赌 提交于 2020-01-02 10:59:14
问题 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

GORM access list index of hasMany association

眉间皱痕 提交于 2020-01-02 07:32:12
问题 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 =

Grails: field access with GORM

て烟熏妆下的殇ゞ 提交于 2020-01-02 05:28:22
问题 Hibernate uses method calls to get the values of domain class properties by default. How can I configure direct field access with GORM? 回答1: It's not directly supported but will be in 1.4. For now you can enable it with a custom Configuration subclass as described at http://grails.1312388.n4.nabble.com/GORM-setting-access-quot-field-quot-td1592837.html#a1594428 I did a small post about subclassing Configuration with links to specific examples at http://burtbeckwith.com/blog/?p=465 回答2: I