gorm

GORM/Grails - add extra column to a joinTable expression

亡梦爱人 提交于 2019-12-12 20:12:47
问题 I have a Domain Class setup similar to this class NewsStory { String headline static hasMany = [channels:Channel] static mapping = { table 'NewsStory' addresses joinTable:[name:'Article_Channel', key:'ArticleId', column:'ChannelId'] } } in the Article_Channel table i need to have an extra column populated called ArticleType say. Its value will always be the same e.g. 'news' for this domain class, but will be differnt for others e.g. 'blog' Channel is just something like 'Security' etc Is

How can I access GORM object properties in a GroovyScriptCommand?

妖精的绣舞 提交于 2019-12-12 19:36:21
问题 I used the Grails create-script command to create my own custom script for rendering source code artifacts based on a GORM domain object. I want to generate a command object that contains the properties of the domain object. I see the properties and methods on the GroovyScriptCommand and TemplateRenderer, but I can't tell how to get a reference to the domain object properties or how to render them in my scaffolding templates. I tried forClass(model.fullName) but it says ClassNotFounException.

Grails GORM 'or' not working with associations

元气小坏坏 提交于 2019-12-12 15:58:02
问题 In the following example, I'd expect Product.searchAll to match both additives and products, but it seems to ignore eq('name', taste) . class Additive { String flavor static belongsTo = [product:Product] } class Product { String name static hasMany = [additives:Additive] static constraints = { name nullable:true } static namedQueries = { searchAll { taste -> or { eq('name', taste) additives { eq('flavor', taste) } } } searchAdditives { taste -> additives { eq('flavor', taste) } }

Cannot attach an object to Hibernate session

落花浮王杯 提交于 2019-12-12 14:00:18
问题 I have 3 domains with these relationships: A hasMany [bs: B] B belongsTo [c: C] C Inside a webflow I do this (simplified version): flow.a = new A(stuff:stuff) flow.a.addToBs(new B(c:C.get(1))) flow.a.addToBs(new B(c:C.get(2))) flow.a.addToBs(new B(c:C.get(3))) and then I try to show all this information on a gsp page: <g:each in="${a.bs}" var="b"> ${b.c.someProperty} </g:each> This is where I get LazyInitializationException . I think I understand why (webflow serializes flow scope) but when I

Including the max and offset criteria inside GORM criteriaBuilder returns an error

我怕爱的太早我们不能终老 提交于 2019-12-12 12:27:13
问题 Can I make this code shorter? if(count == null && from = null) { creditAdviceList = CreditAdvice.findAll { ilike('id', "%$idFilter%") ..... ilike('statusCode', statusCodeFilter) } } else if(count != null && from == null) { creditAdviceList = CreditAdvice.findAll(max: count) { ilike('id', "%$idFilter%") ..... ilike('statusCode', statusCodeFilter) } } else if(count == null && from != null) { creditAdviceList = CreditAdvice.findAll(offset: from) { ilike('id', "%$idFilter%") ..... ilike(

Weird afterInsert / afterUpdate loop in Grails

自古美人都是妖i 提交于 2019-12-12 10:23:44
问题 I have a Note domain class, and when a new note is saved I need to create for it a NoteEvent , recording for posterity that the note has been created. Note has a collection of NoteEvents , and each NoteEvent keeps track of which Note it belongs to. The Note class: class Note { String noteText Date dateCreated static hasMany = [events : NoteEvent] } The NoteEvent class: class NoteEvent { Date dateCreated String type static belongsTo = [note : Note] } To handle the saving of new NoteEvents when

GORM mappedBy and mapping difference

你。 提交于 2019-12-12 09:59:08
问题 In the GORM what is the difference between mappedBy and mapping ? static mapping = { ... } static mappedBy = { ... } 回答1: mapping mapping simply tells GORM to explicitly map one or more Domain properties to a specific database column. class Person { String firstName static mapping = { table 'people' id column: 'person_id' firstName column: 'First_Name' } } in this case for instance I am instructing GORM to map the id attribute to the column person_id of the people table and the firstName

concurrent transaction in grails resulting in database stale state exception

孤者浪人 提交于 2019-12-12 09:56:52
问题 following is my code that is run on an api call.The below code is in a grails service which are transactional by default.But even after locking the row,I am getting this error : Message: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) .There is just one plan in database so for loop is run just once.but there are concurrent calls to api which are causing error.Please help me fix this def updateAllPlans(def user,def percentComplete,def chapterId){ def

Sharing environment settings in datasource.groovy

只愿长相守 提交于 2019-12-12 09:53:43
问题 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

Grails global constraints

旧街凉风 提交于 2019-12-12 09:43:57
问题 In version 1.2, Grails introduced global constraints. I tried adding the following to Config.groovy grails.gorm.default = { constraints { notBlank(nullable:false, blank:false) } } Then using it in one of my domain classes static constraints = { email(email: true, unique: true, shared: 'notBlank') } But when I save a user with a null e-mail address, no errors are reported, why? Thanks, Don 回答1: I've never tried to make global constraints, but I can tell you that if you want to mark a field as