gorm

Using lazy property fetching in Grails / Gorm

被刻印的时光 ゝ 提交于 2019-11-29 17:12:26
is there any way to use lazy property fetching in Grails / Gorm ? somtehing like: @Basic(fetch = FetchType.LAZY) annotation ( it also works with left join fetch?) (for example lazy loading of an String attribute) This question was asked on the grails-user mailing list here . There are a few different options discussed. Take a look at http://grails.org/doc/latest/guide/single.html#5.5.2.8%20Eager%20and%20Lazy%20Fetching EDIT By the way have you tried?: static mapping = { property lazy:true } 来源: https://stackoverflow.com/questions/5880564/using-lazy-property-fetching-in-grails-gorm

my own id in GORM

谁都会走 提交于 2019-11-29 17:08:31
问题 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

HibernateException: No Session found for current thread when GORM query moved into another domain class

送分小仙女□ 提交于 2019-11-29 14:14:36
In grails, I have a Domain class and can be queried in BootStap.groovy def xref = AppXref.find{user_nm == 'john'} However, once I moved the code into a method of another Domain class I will have the following error. Servlet.service() for servlet [default] in context with path [/myapp] threw exception Message: Could not obtain current Hibernate Session; nested exception is org.hibernate.HibernateException: No Session found for current thread Here is my hibernate config in Config.groovy hibernate { cache.use_second_level_cache = true cache.use_query_cache = false // cache.region.factory_class =

Grails: setting transient fields in the map constructor

北城以北 提交于 2019-11-29 12:25:51
I'm trying to persist Maps of properties as single JSON-encoded columns, as shown in this question . The problem I'm having is that apparently transient properties cannot be set in the default map constructor . Given any transient field: class Test { //... String foo static transients = ['foo'] } It seems that the map constructor (which Grails overrides in various ways) simply discards transient fields: groovy:000> t = new Test(foo:'bar') ===> Test : (unsaved) groovy:000> t.foo ===> null While direct assignment (through the setter method) works as expected: groovy:000> c.foo = 'bar' ===> bar

What is the difference between withTransaction and withSession in grails?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 11:52:26
问题 I know one gets the underlying session and the other a reference to the current transaction status; however, what are the differences between them and what would be an example use-case for each? My requirement is to batch save some records within a Service method block. 回答1: withTransaction is a bit hackish because it allows you to do transactional work anywhere, but it's best to separate your concerns and do the work in a transactional service. A service is transactional by default unless

Seeing only your own data in Grails

隐身守侯 提交于 2019-11-29 11:40:56
This seems like a fundamental question, but I haven't found a clear answer. I'm using the spring-security-core plugin with Grails, and I have S2Users who have many Portfolios, and Portfolios have many Transactions. When I go to a scaffolded view to examine Transactions, how do I know that each user is only seeing his own Transactions? Conversely, how can I create a user that can see all Transactions of all users? It's not clear to me what the default behavior is, and how Grails/Spring-Security knows whether a particular domain class should be visible to everyone versus ones that are only for

Multiple hasMany relationships to same domain class in Grails

北慕城南 提交于 2019-11-29 09:35:54
问题 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:

Grails - Saving multiple object, Rollback all object if one fails to save

假如想象 提交于 2019-11-29 08:53:57
I need to save multiple object at once, and rollback all if one object fails to save. For example : class Transaction { Item item; } class Item { date lastTransaction; } If I create new Transaction, I need to change lastTransaction value and save the item. If I failed to save the item, I need to rollback the Transaction (vice versa). Any ideas? Yuck. Don't throw exceptions to roll back transactions. You're incurring a pretty high cost to take advantage of a side effect where the transaction manager, assuming that a runtime exception means that you're not in control, automatically rolls back

Grails 1.0.3 Upgrade Problems

随声附和 提交于 2019-11-29 08:50:53
I am trying to upgrade a Grails 1.0.3 project to 1.3.7 and am having what I believe are related issues. The old project has Hibernate xml files in conf/hibernate/Domain1.hbm.xml I am guessing that GORM didn't exist in 1.0.3? Do I need to essentially convert what is in the xml files into Groovy code in the Domain classes in domain/ Any other details are helpful. Thanks. UPDATE - All of these changes are the result of a org.hibernate.DuplicateMappingException It looks like I can just move the domain files: Relevant Post Is that really what I want to do though? My understanding is that with GORM

Joda time DateTime incorrectly stores in database

别说谁变了你拦得住时间么 提交于 2019-11-29 08:41:25
问题 I'm storing JodaTime DateTime field to timestamptz column by using org.jadira.usertype:usertype.jodatime:1.9 . App server has +4 time zone. DB server +9 time zone. new DateTime() results in ${currentTime+1hour}+9 where +9 is time zone (correct value is ${currentTime+5hours)+9 ). I haven't found any related topics. java.util.Date stores correctly. Domain object has the following mapping property: static mapping = { dateCreated sqlType:'timestamptz' } How can I store DateTime correctly? 回答1: