gorm

How can I create a dynamic domain class in Grails

◇◆丶佛笑我妖孽 提交于 2019-12-23 15:01:09
问题 How can I create a dynamic domain class in Grails. Let's say I want to create a new domain class whose class name and properties is known in the run-time. How to create it and persist it in Grails? Many thanks, 回答1: There's a plugin for that: http://www.grails.org/plugin/dynamic-domain-class 回答2: the plugin seems to be abandoned, and in the google group of the project the deveoper say that there is some important issue and he said we can't using it in production, and there is no evolution

GORM Relations without dependent delete

爱⌒轻易说出口 提交于 2019-12-23 13:06:13
问题 I have two domain classes User and Node. The following conditions should hold. a User can have zero or one node a Node can have one to n User (it is always initialized with a User instance) if you delete a Node the User will not be deleted if you delete a User the reference in the Node will be deleted I tried: class User { Node node } class Node { // constructor Node(User user) { addToUsers(user) save() } hasMany = [users: User] } The former does not work. It does not work because when you

Grails domain obj action argument and association data binding

一笑奈何 提交于 2019-12-23 12:32:33
问题 I know Grails v2.3 introduced some changes to the way data binding works, but I'm struggling to figure out how to get automatic association binding to work when I have an domain obj as the action argument. For instance, with a couple of simple domain objects: class Author { String name List books static hasMany = [books: Book] } class Book { String name static belongsTo = [author: Author] } and controller action: def doSomething(Author a) { // only simple properties appear to be bound at this

Explain belongsTo in Grails

不羁的心 提交于 2019-12-23 07:51:34
问题 From the Grails belongsTo documentation, what is the use of class Book { static belongsTo = Author } What is the impact of cascading operations on Book, when CRUD operations performed on Author? EDIT: Thanks for your responses, may be i didn't specify my question correctly. I would like to know the difference between static belongsTo [author:Author] vs static belongsTo = Author 回答1: belongsTo is helpful if you need a reference back to the owning object. In this case it is likely that an

GROM create needless table with many-to-many mapping

无人久伴 提交于 2019-12-23 04:43:07
问题 I have problem about many-to-many mapping. [Case] Account owns Community(owner) Community has many Account(members) GORM create four tables: ACCOUNT COMMUNITY COMMUNITY_MEMBERS COMMUNITY_OWNER GORM creates a table "COMMUNITY_OWNER (ACCOUNT_ID, OWNER_ID)". Why GORM creating this? This table is not used.(Please look at Hibernate log) I want GORM to not create COMMUNITY_OWNER. My mapping is wrong? Related Question: cascade delete with many-to-many mapping in Grails [Domain Class] class Account {

Grails GORM criteria on null association

南笙酒味 提交于 2019-12-23 04:35:07
问题 I have a domain object with an associated domain object which I'd like to be able to search on as part of a query. Using the Book model as an example, I'd have: public class Book{ Author author String title } public class Author{ String name } .. and want to filter like: def book = Book.withCriteria{ or{ ilike(title, "%" + params.filter + "%") author{ ilike("name", "%" + params.filter + "%") } } } The problem I'm having is that if I include author in the query, then any "Books" with a null

Grails GORM criteria on null association

喜你入骨 提交于 2019-12-23 04:35:05
问题 I have a domain object with an associated domain object which I'd like to be able to search on as part of a query. Using the Book model as an example, I'd have: public class Book{ Author author String title } public class Author{ String name } .. and want to filter like: def book = Book.withCriteria{ or{ ilike(title, "%" + params.filter + "%") author{ ilike("name", "%" + params.filter + "%") } } } The problem I'm having is that if I include author in the query, then any "Books" with a null

Grails 3.1.0.M2 Database Reverse Engineering

感情迁移 提交于 2019-12-23 02:25:13
问题 Need of help. I am new to Grails, My question is How to do db-reverse-engineer.? I did it in Grails 2.5.1 but I am struggling with Grails 3.1.0.M2 version. Thanks in advance. 回答1: There's no plugin for Grails 3. I started to convert the older one but it's more work than I was expecting because it has to work with Hibernate 4, and the old plugin only works with Hibernate 3. But the generated files wouldn't be any different in Grails 3 than in Grails 2 since GORM has stayed rather consistent.

Sorting query results according to parent property in grails

余生长醉 提交于 2019-12-23 01:21:49
问题 Is it possible in grails to sort query results according to a property of a parent class in a relationship. E.g. I have a user domain class which has a one to many relationship with a list of Tasks. When showing the list page of the Tasks domain class, I want to be able to sort the list of tasks by the associated User name. class User { String name String login String group List tasks = new ArrayList() static hasMany = [tasks:Task] } class Task { String summary String details User user static

lazy column loading in Grails domain class

本秂侑毒 提交于 2019-12-22 18:02:05
问题 I have a domain class like this: class Document { String mime; String name; byte[] content; static mapping = { content lazy:true; } } and I'd like to enable lazy loading to the "content" column, because the application does some stuff without the need of access to this column. But the lazy:true option didn't work... any idea or workaround? 回答1: What do you mean by the application does some stuff? and what are you trying to establish? FYI. eager and lazy loading usually has to do with