gorm

Many-to-Many link tables in grails (GORM) / hibernate

核能气质少年 提交于 2019-11-29 08:02:10
I'm playing aroud with Grails and am finding the ORM stuff tedious because I don't fully understand what I'm doing when it comes to domain classes. I'm hoping someone can put me back on track Consider the following Test Job One:Many Hardware Used on Job Many:One Physical Hardware ...this is analogous to the classic Order, OrderLine, Product scenario seen in university DB examples I've created the following domain classes class Job { String jobName String jobDescription } class HardwareOnJob { static hasMany = [ jobs:Job, physicalHardware:PhysicalHardware ] static belongsTo = Job String role }

Grails request parameters encoding issue in Tomcat

橙三吉。 提交于 2019-11-29 07:40:21
My grails app will not decode request parameters correctly. In config.groovy: grails.views.gsp.encoding = "UTF-8" grails.converters.encoding = "UTF-8" All my gsp's use contentType="text/html; charset=UTF-8" on the page directive as well as <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> in the head element. However, when i receive the posted parameters from the param object in my controller, the app just prints garbage... I'm using Grails 1.3.7 version deployed over Tomcat 5. Other installed plugins except tomcat: hibernate 1.3.7 jquery 1.7.1 spring-security-core 1.2.6

Grails/GORM default fetch strategy: When to set fetchMode to “eager”? (eager vs. lazy)

别等时光非礼了梦想. 提交于 2019-11-29 04:37:25
What are some general guidelines on when to set fetchMode to "eager" in a domain class? Pros and cons of fetchMode "eager" vs. the default "lazy"? Please include some specific examples/use-cases showing when to use "eager" (fetchMode=eager), and when not to (fetchMode=lazy). Basically lazy loading has more benefits than the eager alternative (performance, use of resources) . Since it's the default grails setting for all relations (since Grails 1.1) you should generally not configure it for eager fetching, unless you experience certain issues. Such as: Sharing a domain instance accross

GORM createCriteria and list do not return the same results : what can I do?

孤人 提交于 2019-11-29 04:29:21
I am using Nimble and Shiro for my security frameworks and I've just come accross a GORM bug. Indeed : User.createCriteria().list { maxResults 10 } returns 10 users whereas User.list(max: 10) returns 9 users ! After further investigations, I found out that createCriteria returns twice the same user (admin) because admin has 2 roles !!! (I am not joking). It appears that any user with more than 1 role will be returned twice in the createCriteria call and User.list will return max-1 instances (i.e 9 users instead of 10 users) What workaround can I use in order to have 10 unique users returned ?

Grails/GORM: The meaning of belongsTo in 1:N relationships

旧时模样 提交于 2019-11-29 04:29:17
In an ordinary one-to-many mapping the "one"-side is the owner of the association. Why would anyone use the belongsTo-mapping for such a mapping? Am I missing some side-effect of specifying belongsTo? In other words: what are the effects of specifying a belongsTo-mapping in GORM vs. not specifying it? Whether to specify belongsTo depends upon the type of referential action you want. If you want Grails to do On Delete, CASCADE referential action, then DO specify belongsTo . If you want Grails to do On Delete, RESTRICT referential action, then DON'T specify belongsTo . e.g. // "belongsTo" makes

Using Grails GORM standalone

我的梦境 提交于 2019-11-29 02:50:38
问题 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? 回答1: 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

Proper Implementation of clone() For Domain Classes to duplicate a Grails domain instance

天涯浪子 提交于 2019-11-29 02:25:47
I have several domain classes for which the user interface includes a "duplicate" command. As part of the implementation of those commands, I have implemented clone() methods in the corresponding domain classes. I have been trying to correct my bad habit of improperly implementing clone() (in general) based on use of " new " rather than "super.clone()," so as soon as I thought about doing the same for my Grails domain classes, I wondered how using super.clone() to obtain a clone might interact with GORM / Hibernate persistence. In particular, I was wondering about the proper way to handle the

Is it possible to map a table name for a domain object dynamically in grails?

放肆的年华 提交于 2019-11-29 00:27:36
I have a domain that looks something like class Foo { String name static mapping = { table 'foo' } } but I want to make is more like : static mapping = { table "foo_${dynamicVarThatComesFromRequest}" } What I want to know is whether this is even possible? Thanks! It is possible. You can add a Hibernate interceptor to process all SQL statements and parse/replace some token in the table name you enter in the mapping with the actual table name you want to use. src/groovy/DynamicTableNameInterceptor.groovy : import org.hibernate.EmptyInterceptor public class DynamicTableNameInterceptor extends

Grails GORM domain association across two datasources

好久不见. 提交于 2019-11-28 23:49:58
Is it possible to have an association between two domain classes (i.e. belongsTo ) if the other domain class uses a different datasource? The two datasources are different database drivers too. I suspect this may not be possible, but I wanted to reach out to the community here to see if it was possible. Right now I'm trying to do it and I am getting the usual suspected Hibernate error: Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table domain_class_A refers to an unmapped class: DomainClassB Sample: class DomainClassA { static

How to order by more than one field in Grails?

為{幸葍}努か 提交于 2019-11-28 17:47:40
Is there a way to get a list ordered by two fields, say last and first names? I know .listOrderByLastAndFirst and .list(sort:'last, first') won't work. Hates_ This old solution no longer works. Please see mattlary's answer below You may have to write a custom finder in HQL or use the Criteria Builder. MyDomain.find("from Domain as d order by last,first desc") Or def c = MyDomain.createCriteria() def results = c.list { order("last,first", "desc") } mattlary Hates_ criteria answer didn't seem to work for me; putting "last,first" in order will only cause exceptions saying, "Property 'last,first'