gorm

Hibernate 2nd level cache in a Grails app

烈酒焚心 提交于 2019-11-28 15:47:20
问题 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

How to configure Grails 3.1.1 to use Hibernate 5

被刻印的时光 ゝ 提交于 2019-11-28 14:13:14
How do I make Grails 3.1.1 user Hibernate 5? The following actions report Hibernate version 4.3.11.Final: In Grails 3.1.1 grails create-app hello311 edit BootStrap.groovy as shown below grails run-app Console shows: Hibernate version is: 4.3.11.Final class BootStrap { def init = { servletContext -> println "Hibernate version is: ${org.hibernate.Version.getVersionString()}" } def destroy = {} } My build.gradle is unedited. The create-app command resulted in the following build.gradle file: buildscript { ext { grailsVersion = project.grailsVersion } repositories { mavenLocal() maven { url "https

Using groupProperty and countDistinct in Grails Criteria

心不动则不痛 提交于 2019-11-28 11:30:48
I'm using Grails 1.2.4. I would like to know on how can I sort by "countDistinct" (descending) and with groupProperty inside a projections. Here are my domains: class Transaction { static belongsTo = [ customer : Customer, product : Product ] Date transactionDate = new Date() static constraints = { transactionDate(blank:false) } } class Product { String productCode static constraints = { productCode(blank:false) } } In MySQL terms, this is what I want: select product_id, count(product_id) from transaction group by product_id order by count(product_id) desc In general term, I would like to get

Using lazy property fetching in Grails / Gorm

不羁的心 提交于 2019-11-28 10:48:43
问题 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) 回答1: This question was asked on the grails-user mailing list here. There are a few different options discussed. 回答2: 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

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

孤人 提交于 2019-11-28 08:30:20
问题 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

Grails query not using GORM

巧了我就是萌 提交于 2019-11-28 06:57:38
What is the best way to query for something without using GORM in grails? I have query that doesn't seem to fit in the GORM model, the query has a subquery and a computed field. I posted on stackoverflow already with no response so I decided to take a different approach. I want to query for something not using GORM within a grails application. Is there an easy way to get the connection and go through the result set? In a service or controller, you can add a dependency injection for the dataSource bean and use groovy.sql.Sql or JDBC directly if you're a masochist. import groovy.sql.Sql class

Grails 2 - How to dynamically call multiple datasources

只愿长相守 提交于 2019-11-28 05:24:26
问题 I have two named data sources in my Grails app (Grails 2.0.3)... dataSource_a { // ... } dataSource_b { // ... } I'd like the ability to dynamically change what datasource I'm accessing, based on some kind of parameter. I could do something like this... def findPeople(datasource) { if (datasource == 'a') { return Person.a.list() } else if (datasource == 'b') { return Person.b.list() } } What I was really hoping to be able to do, though, is something like this... def findPeople(datasource) {

Seeing only your own data in Grails

时光毁灭记忆、已成空白 提交于 2019-11-28 05:04:38
问题 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

Retrieving a list of GORM persistent properties for a domain

时间秒杀一切 提交于 2019-11-28 04:31:35
What's the best/easiest way to get a list of the persistent properties associated with a given GORM domain object? I can get the list of all properties, but this list contains non-persistent fields such as class and constraints . Currently I'm using this and filtering out the list of nonPersistent properties using a list I created: def nonPersistent = ["log", "class", "constraints", "properties", "errors", "mapping", "metaClass"] def newMap = [:] domainObject.getProperties().each { property -> if (!nonPersistent.contains(property.key)) { newMap.put property.key, property.value } } There seems

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

落花浮王杯 提交于 2019-11-28 02:17:34
问题 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? 回答1: 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