gorm

my own id in GORM

佐手、 提交于 2019-11-30 11:20:48
I tried to change the standard 'id' in grails: calls Book { String id String title static mapping { id generator:'assigned' } } unfortunately, I soon noticed that this breaks my bootstrap. Instead of new Book (id:'some ISBN', title:'great book').save(flush:true, failOnError:true) I had to use def b = new Book(title:'great book') b.id = 'some ISBN' b.save(flush:true, failOnError:true) otherwise I get an 'ids for this class must be manually assigned before calling save()' error. but that's ok so far. I then encountered the same problem in the save action of my bookController. But this time, the

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

只愿长相守 提交于 2019-11-30 10:21:41
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)? 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 Employee { String name static hasMany = [ subordinates: Employee ] static belongsTo = [ manager: Employee ] static

Multiple hasMany relationships to same domain class in Grails

做~自己de王妃 提交于 2019-11-30 07:26:18
I'm using Grails, and I have a domain model with multiple hasMany attributes to the same domain class, which looks like this: static hasMany = [ posts : Post, likes : Post, dislikes : Post ] The problem that I'm running into is that when I add something to the posts list, it also somehow makes it into the likes and dislikes lists. At least, that's how it looks when I iterate through each of those lists. I think that the issue is that I also have the following relationship in my Post domain: static belongsTo = [ contributer : Contributer ] What is the best way of going about configuring these

Using Grails GORM standalone

孤街醉人 提交于 2019-11-30 05:16:14
I'm currently wondering how it is possible to use the Groovy ORM Layer from Grails standalone outside of the Grails Framework. There is a Documentation Entry for doing so, but the ZIP file only links to an empty page . I downloaded Grails 1.2-M3 but I couldn't find anything in the docs either. Does anybody know what the current state is and how to accomplish this? AFAIK it is possible to use GORM standalone since Grails 1.1. This allows you to use GORM as your ORM without using the full Grails framework However, I don't think it's possible to use GORM outside of Spring (which is the foundation

Selective deep rendering of hasMany relationships in grails

﹥>﹥吖頭↗ 提交于 2019-11-30 04:16:31
问题 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: {

Grails: Projection on many tables?

耗尽温柔 提交于 2019-11-30 03:55:30
问题 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

Grails domain class relationship to itself

旧巷老猫 提交于 2019-11-29 22:17:30
问题 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? 回答1: 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

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

你。 提交于 2019-11-29 21:07:52
问题 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 {

Hibernate 2nd level cache in a Grails app

时间秒杀一切 提交于 2019-11-29 20:26:58
Part I In a Grails app, I understand that you enable the 2nd level cache per domain class by adding static mapping { cache true } By default the 2nd level cache is only used when get() is called, but it can also be used for criteria queries and dynamic finders by adding cache true to the query. However, I'm still not sure I understand how the query cache works. My best guess is that: there are separate query caches for each domain class, e.g. one for Book and another for Author before a query like Author.findByName('bob', [cache: true]) is executed, a cache key is computed, which is based on

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

半城伤御伤魂 提交于 2019-11-29 17:43:37
问题 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