gorm

grails domain class .list() method with params

走远了吗. 提交于 2019-12-11 09:27:24
问题 I have two domains that are connected with one-to-many relation - One User may have many Associations. I want to view all associations that belong to this user. I'm using scaffolding plugin. So code that should return list of Associations in AssociationController looks lile this: def index(Integer max) { respond Association.list(params), model:[associationInstanceCount: Association.count()] } And on the User view page I have the following code: <g:form controller="Association" > <fieldset

Grails: MySQL and mongoDB together

眉间皱痕 提交于 2019-12-11 09:21:43
问题 I am new to GRAILS. I am trying to use MySQL and MongoDB in one web-app. Can someone have a quick look on my BuildConfig.groovy and datasource.groovy and suggest me the correct way ahead. buildconfig.groovy grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0) grails.project.class.dir = "target/classes" grails.project.test.class.dir = "target/test-classes" grails.project.test.reports.dir = "target/test-reports" grails.project.work.dir = "target/work"

Grails project: Gorm or JPA/Hibernate annotations for legacy db mapping?

佐手、 提交于 2019-12-11 08:44:42
问题 In a grails app, I have to create a bunch of grails domain classes mapped to a very old db. This very old db is using a lots of "funky" unreadable names for tables and columns. These tables contains (too) often (too) many columns. I was thinking of using the static mapping for all the relationship and using the JPA annotations for the columns names (almost all columns needs to be renamed and the mapping section will be elephantine) Is this kind of mix is possible ? If yes, is it something

can GORM duplicate whole object?

我的梦境 提交于 2019-12-11 08:36:16
问题 we are using grails to develop some web application For Domain class that have child class , I'm wondering if we can duplicate whole object including all child object that belong to Parent ? Thank you 回答1: As given in the comments, you can extend gorm with a clone method. However, a very simple solution if you don't want to mess with the gorm api is to detach the existing object and just "resave" it. Note that this won't perform a deepClone . Steps: Null the id. Update fields that should

findAll() Not Returning Correct Object Type

不羁岁月 提交于 2019-12-11 08:27:53
问题 ItemTag objects contain an Item object and a Tag object. (These are Java domain objects.) This simple query works as expected. I get back a list ItemTags and can do all the wonderful things that ItemTags are supposed to do: def theTags1 = ItemTag.findAll("from ItemTag b") For example: println(theTags1[0].tag.tag) gives me this as expected: Pilgrim's Progress However, as soon as I add another table to the criteria, instead of getting a list of ItemTags, I just get a list of generic objects. e

Overriding default `maxSize` in domain class

拥有回忆 提交于 2019-12-11 06:35:26
问题 I've set a default value, for maxSize constraint, to all my domains, using config.grails.gorm.default.constraints = { ... '*'(..., maxSize: 80) ... } Now, I want to override this value inside my domain class; I can do that by defining it there static constraints = { ... prop maxSize: 120 ... } But how could I make it unlimited, for instance? I wish it could have been done by providing -1 . Or the String and other Collection s could have been handled differently, by using two different

How can I add a criteria to a grails criteria to limit results based on a filtered association?

家住魔仙堡 提交于 2019-12-11 06:33:31
问题 In my old java code I could do this to "join" another table in a hibernate query and filter results based on it. final Criteria brokerageCriteria = userCriteria.createCriteria("brokerage"); if (queryDto.getBrokerageID() != null) { brokerageCriteria.add(Restrictions.eq("id", queryDto.getBrokerageID())); } In this example it would filter users who are a member of a specific brokerage only (each user has one brokerage). As you can see I can easily join other tables that are associated in the

Grails GORM auto update issue

我是研究僧i 提交于 2019-12-11 06:14:47
问题 Updated post: In a Controller if I do this: def obj = new Test(name:"lol") obj.save(flush:true) obj.name = "lol2" //a singleton service with nothing to do with obj testService.dostuff() /* "obj" gets persisted to the database right here even before the next println */ println "done" Can anyone please explain me why is this happening with Grails 1.3.7 and not with Grails 2? What is the reason? I know I could use discard() and basically restructure the code but I am interested in what and why

Grails programmatic transaction handling

99封情书 提交于 2019-12-11 04:03:58
问题 My Grails app has a a service method that updates a list of artists from last.fm's web service. @Transactional(propagation = Propagation.NOT_SUPPORTED) void updateLastFmArtists(Range idRange = null) { Artist.list().each { Artist artist -> // We could be updating a lot of artists here, the process could take up // to an hour and we don't want to wrap all that in a single transaction Artist.withTransaction { status -> try { updateArtistInfo(artist) } catch (IOException ex) { status

Grails withNewSession does not flush

旧街凉风 提交于 2019-12-11 03:49:49
问题 In a grails Domain a have implemented the beforeDelete as follow class Shop { def beforeDelete() { Shop.withNewSession { Client.findAllByShop(this)*.shop = null } } } But the client shop null value is not persisted to the DB. If I add a manual session flush class Shop { def beforeDelete() { Shop.withNewSession { s2-> Client.findAllByShop(this)*.shop = null s2.flush() s2.clear() } } } It works, the client shop value are nulled in the db. Is this a Grails bug or I have misunderstand the