Questions tagged [grails-orm]

GORM is Grails' object relational mapping (ORM) implementation. Use [go-gorm] for the Go ORM.

GORM is Grails' object relational mapping (ORM) implementation. Under the hood it uses Hibernate 3 (an extremely popular and flexible open source ORM solution) but because of the dynamic nature of Groovy, the fact that it supports both static and dynamic typing, and the convention of Grails there is less configuration involved in creating Grails domain classes.

GORM classes also support Hibernate's query language HQL, a very complete reference for which can be found Chapter 16. HQL: The Hibernate Query Language of the Hibernate documentation.

It's also possible to GORM standalone in a non-Grails project.

Resources:

Grails User Guide for GORM

Related tags:

4244 questions
121
votes
13 answers

Why do I get a "Null value was assigned to a property of primitive type setter of" error message when using HibernateCriteriaBuilder in Grails

I get the following error when using a primitive attribute in my grails domain object: Null value was assigned to a property of primitive type setter of MyDomain.myAttribute org.hibernate.PropertyAccessException: Null value was assigned to a…
Peter
  • 5,793
  • 4
  • 27
  • 31
83
votes
15 answers

Found shared references to a collection org.hibernate.HibernateException

I got this error message: error: Found shared references to a collection: Person.relatedPersons When I tried to execute…
nightingale2k1
  • 10,095
  • 15
  • 70
  • 96
52
votes
3 answers

Difference between findAll, getAll and list in Grails

With Grails there are several ways to do the same thing. Finds all of domain class instances: Book.findAll() Book.getAll() Book.list() Retrieves an instance of the domain class for the specified id: Book.findById(1) Book.get(1) When do you use…
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
43
votes
10 answers

How to order by more than one field in Grails?

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.
TheBrain
  • 533
  • 1
  • 4
  • 11
42
votes
5 answers

Do I ever need to explicitly flush GORM save calls in grails?

I have a strange situation which appears to indicate a GORM cacheing problem //begin with all book.status's as UNREAD Book.list().each { book.status = Status.READ ; book.save() } println (Book.findAllByStatus (Status.READ)) //will print an empty…
Akusete
  • 10,704
  • 7
  • 57
  • 73
40
votes
1 answer

Hibernate 2nd level cache in a Grails app

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…
Dónal
  • 185,044
  • 174
  • 569
  • 824
39
votes
3 answers

Binding JSON to nested Grails Domain Objects

I'm developing a RESTful interface which is used to provide JSON data for a JavaScript application. On the server side I use Grails 1.3.7 and use GORM Domain Objects for persistence. I implemented a custom JSON Marshaller to support marshalling the…
frow
  • 874
  • 8
  • 13
34
votes
2 answers

Upgrading Grails MongoDB GORM broke projections on list properties

I am using Criteria with projections to get a list of tags on my Account domain. Like this: def tags = Account.createCriteria().list { projections { property("tags") } } My Account domain: class Account { static mapWith = "mongo" …
Haleystorm
  • 374
  • 2
  • 4
31
votes
4 answers

Retrieving a list of GORM persistent properties for a domain

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…
lambmj
  • 1,843
  • 2
  • 21
  • 27
26
votes
1 answer

Benefits of object.get() vs object.read() in Grails

I was skimming some of the Grails documentation and found this bit about the read() method in Grails. If I'm understanding this correctly, you can pull a "read-only" version of an object from the database that will only be saved on an explicit…
Mike Caputo
  • 1,156
  • 17
  • 33
25
votes
3 answers

How do you bulk delete records in Grails/GORM?

I have a table which has records that need to be periodically cleared according to a set of criteria. I was expecting that I could use the criteria builder to just delete the records, but that fails because there is no delete method on…
Simon
  • 78,655
  • 25
  • 88
  • 118
24
votes
4 answers

grails hasOne vs direct member variable

Let's say I have a grails domain class that looks like class Person { Address address } I could also declare it as class Person { static hasOne = [address:Address] } The second way would move the foreign key to the Address table rather than…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
22
votes
10 answers

Overriding dateCreated for testing in Grails

Is there any way I can override the value of dateCreated field in my domain class without turning off auto timestamping? I need to test controller and I have to provide specific domain objects with specific creation date but GORM seems to override…
jjczopek
  • 3,319
  • 2
  • 32
  • 72
22
votes
3 answers

criteria uses "inner join" instead "left join" approach by default making my query work not the way I planned

The question is: how do I make GORM generate left joins instead of inner joins in this particular example? Testbed: Given classes A, B and C: class A{ B someObject } class B{ C importantObject } class C{ boolean interestingFlag } I…
Andrzej Bobak
  • 2,106
  • 3
  • 28
  • 36
21
votes
2 answers

Why grails throwing null pointer exception while accessing hasMany relationship first time?

I have a strange problem. I have two domain classes User and Post with fields: class User { String name static hasMany = [posts: Post] static constraints = { } } and class Post { String content long date = System.getTimeInMillis() …
mj.scintilla
  • 638
  • 1
  • 9
  • 20
1
2 3
99 100