gorm

Grails: Projection on many tables?

假装没事ソ 提交于 2019-11-30 20:20:24
I have some problems with projection in Grails. Could you please help me review them and suggest solutions for me? I want to query data on many tables which has many-to-one relationship and projection on some properties on both of them. For example: class Person { int id String name String address static hasMany = [cars : Car] } class Car { int id String brand long price Person owner static belongsTo = [owner : Person] } So, how can I use just one query withCriteria (apply projection) to get information of a specified car (include brand, price, and the owner name)? Is it possible to use: Car

Selective deep rendering of hasMany relationships in grails

戏子无情 提交于 2019-11-30 20:09:18
For the following domain model: class Route { String name static hasMany = [checkPoints:CheckPoint] static belongsTo = [someBigObject:SomeBigObject] static mapping = { checkPoints lazy: false } } I need to return a specific Route as a JSON from a web service. And I want this JSON to contain all the checkPoints but no other compositions (i.e.: someBigObject ). If I do def route = Route.findById(id) render route as JSON all I got is the id's of the checkPoints , no other field is fetched: { "class": "com.example.Route", "id": 1, "checkPoints": [ { "class": "CheckPoint", "id": 1 }, { "class":

GORM: mapping large text fields database agnostically

℡╲_俬逩灬. 提交于 2019-11-30 19:04:10
问题 I have a Grails application that will run against either a SQL Server or Oracle backend. I am using GORM as an ORM. I want to map a large text field in a way that supports both database types. In my Grails domain class I have something like: class Note { String content static constraints = { content nullable: false, blank: false } } I then declare database tables that look like this: -- oracle CREATE TABLE NOTE ( id NUMBER(19, 0) NOT NULL, version NUMBER(19, 0) NOT NULL, content CLOB NOT NULL

Tree structure in GORM (grails)

寵の児 提交于 2019-11-30 18:58:04
问题 I'm trying to define a tree structure in GORM. Here is my model: class Tree { String name Level rootLevel static hasOne = [rootLevel: Level] static hasMany = [levels: Level] static mappedBy = [levels:"parentTree"] } class Level { String name Tree parentTree Level parentLevel Set<Level> subLevels static belongsTo = [parentTree: Tree] static hasMany = [subLevels: Level] } Insertion seems to work fine, but when I can't load a Tree with many levels and sublevels. I guess I missed something in the

How to design domain classes in Grails?

回眸只為那壹抹淺笑 提交于 2019-11-30 18:36:23
问题 Given these functional requirements: User Management Administrator Librarian Borrower *The users have the option of logging-in via OpenID. Property Management Book Memorandum Circular License Normally, I would implement these in Java as: interface User {} class Librarian implements User {} class Administrator implements User {} class Borrower implements User {} class OpenID {} //all Users HAS AN OpenID attribute (NULL if non-openId login) interface Property{} class Book implements Property{}

Grails: Create dynamic SQL-Connection

[亡魂溺海] 提交于 2019-11-30 18:34:17
问题 For my application I need dynamic database connections at runtime. I know, there are ways to create multiple datasources but they are not that dynamically I think. Scenario: A user can enter database credentials and connect to a remote database to import single rows and tables to an other database. For this purpose I need to connect to the remote database dynamically. I've tried to do that in a service like they've said in If I use groovy sql class in grails, does it use the grails connection

Grails domain class relationship to itself

笑着哭i 提交于 2019-11-30 15:32:26
I need a way to be able to have a domain class to have many of itself. In other words, there is a parent and child relationship. The table I'm working on has data and then a column called "parent_id". If any item has the parent_id set, it is a child of that element. Is there any way in Grails to tell hasMany which field to look at for a reference? This is an example of what you are looking for (it's a snippet code I am running and it generates column parent_id). I don't think you need SortedSet: class NavMenu implements Comparable { String category int rank = 0 String title Boolean active =

Grails 2.x createCriteria 'or' doesn't work for nested associations

ぃ、小莉子 提交于 2019-11-30 14:49:00
It seems that in Grails 2.x, if you have a domain class association, and you try to run a createCriteria using or on that relation + another query, the or will ignore the other query and just use the results of the nested association. I realize this may be a little confusing, so here is an example: class Passenger { Long id Boolean isDriving } class Car { Long id Passenger passenger Boolean isMoving static constraints = { passenger nullable: true } } and a test: class CarIntegrationTests { @Test void testCar() { Passenger passenger1 = new Passenger(isDriving: true) passenger1.save() Car car1 =

GRAILS: Find all children in a self-referenced one-to-many relationship

余生颓废 提交于 2019-11-30 14:20:58
问题 In grails, How would one find all the children in a one-to-many relationship e.g., class Employee { static hasMany = [ subordinates: Employee ] static belongsTo = [ manager: Employee ] } Using a single manager, how would one get the subordinates of all subordinates (like traversing a object graph)? 回答1: The recursive closure works if you don't want to modify the domain. Otherwise you could add a transient property to the Employee domain class like allSubordinates in this example: class

Hibernate/GORM: collection was not processed by flush()

早过忘川 提交于 2019-11-30 11:32:44
I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate.AssertionFailure: collection [com.mycompany.facet.Facet.channels] was not processed by flush() at com.mycompany.member.MemberConnectionService.addOrUpdateContact(MemberConnectionService.groovy:939) Earlier in the transaction I add an object to a collection property of invitingMember . My guess is that the exception is thrown at the line above, because it's only at this point that the object added to the