grails-domain-class

equivalent of InheritanceType.TABLE_PER_CLASS in grails?

时间秒杀一切 提交于 2019-12-20 07:33:13
问题 I want to create 3 separate tables for 3 domain classes: A, B extends A, C extends B But I want their tables to be NOT connected to each other. In hibernate, I would use InheritanceType.TABLE_PER_CLASS, in grails, what would be the equivalent? 回答1: Try to use tablePerHierarchy false class Payment { Integer amount static mapping = { tablePerHierarchy false } } class CreditCardPayment extends Payment { String cardNumber } See more : http://grails.org/doc/latest/guide/single.html#5.5.2.3

Do grails domain classes have to be tied to a database?

筅森魡賤 提交于 2019-12-18 16:23:10
问题 I am a complete noob when it comes to grails (and still very noobish when it comes to groovy) so I apologise if this is a dumb question. I am building a simple web app and I want to control portions of the domain in my app based on file system objects (i.e. directory structure and file type) rather than database data. How easy is it to do this or are the domain objects so entwined with GORM that it is not worth the effort to try? 回答1: I ran into this question myself a couple of weeks ago. You

Do grails domain classes have to be tied to a database?

六眼飞鱼酱① 提交于 2019-12-18 16:22:21
问题 I am a complete noob when it comes to grails (and still very noobish when it comes to groovy) so I apologise if this is a dumb question. I am building a simple web app and I want to control portions of the domain in my app based on file system objects (i.e. directory structure and file type) rather than database data. How easy is it to do this or are the domain objects so entwined with GORM that it is not worth the effort to try? 回答1: I ran into this question myself a couple of weeks ago. You

Grails - Initiating domain class using JSON

走远了吗. 提交于 2019-12-18 08:58:53
问题 I have this simple domain class: class Settings { static constraints = { uid(nullable: false, unique: true) person() } String uid Map person } and a web UI that update the data using a json request: {"uid":1234 , person:{"first_name" : "jhon" , "last_name" : "doe"}} in the controller code: def json = request.JSON; def s = new Settings(json); it seems that s.uid is being set however the s.person Map remains empty. What am I missing? 回答1: You can do something like the following in your

Grails + GORM: What is the default equals() implementation in GORM?

强颜欢笑 提交于 2019-12-13 11:36:01
问题 When I do domainObj1 == domainObj2 in Grails are the objects compared by ID? If not, how are they compared? 回答1: First, you need to understand that GORM/Grails doesn't do anything special when it comes to equals() . Unless you implement your own equals() on your domain class it will default to the Java/Groovy implementation. Which by default means the variables must point to the same instance. Now, what gets slightly confusing is Hibernate. Hibernate uses an identity map (the first-level

Grails Domain class JSON

六月ゝ 毕业季﹏ 提交于 2019-12-13 10:55:12
问题 I have this controller: respond :Alert.list() It gives: [{id: ..}, {id: ..}] What I want: {"alerts":[{"id":...}. {id:..}]} How do I let the respond make into the format I want? I don't want to have a custom JSON marshaller as my dataset is big. What will be the outcome if I do the following than having a custom marshaller? def o = new JSONObject() def arr = new JSONArray() def a = new JSONObject() alerts.each{ a.put("id",it.id) ... arr.add(a) } o.put("alerts",arr) respond o 回答1: Try it like

how set start value for auto increment in grails

一曲冷凌霜 提交于 2019-12-13 02:06:03
问题 I am using my custom auto increment key in my domain class using static mapping = { id generator: 'increment', name: 'personId' } Is it possible to start the auto increment from a particular value , say start from 100 ? 回答1: You can set the initial value of the autoincrement by using the org.hibernate.id.enhanced.SequenceStyleGenerator generator. This generator takes the parameter initial_value , which will be the the value of your first id . (And after that, it will increment by 1, just like

How to populate 2nd combobox(g:select) values on basis of 1st combobox(g:select)?

柔情痞子 提交于 2019-12-12 17:30:16
问题 I'm trying to load 2nd combobox ( g:select ) values on the selection of 1st combobox ( g:select ) value in GSP. Domain classes: class Person { String name static hasMany = [telephones:Telephone] } class Telephone { String tNumber Person person static belongsTo = [person:Person] } GSP: <td> <g:select id="person" name="selectedPersonId" from="${Person.list(sort:name, order:asc)}" value="name" optionValue="name" optionKey="id" noSelection="['0':'--Select--']" /> </td> <td> <g:select id=

add user define properties to a domain class

久未见 提交于 2019-12-12 14:23:35
问题 i have a requirement to allow the user to define some custom field in one of the system entities. do you have any suggestion/pattern/plugin that will help me add this feature to my application. thanks, Meni 回答1: You can add a Map property to your domain class and store arbitrary data there. It's rather limited though. It will generate a table with varchar(255) keys and values, so you need to manage any type conversions yourself, e.g. class Thing { String name Map extraProperties = [:] } int

What is a good workflow for database migration in Grails?

淺唱寂寞╮ 提交于 2019-12-12 08:09:50
问题 I want to use the database-migration grails plugin for database migration. When I start my Grails app the first time all the database tables are created automatically. The production setting in my DataSource.groovy is: production { dataSource { dbCreate = "update" url = "jdbc:mysql://localhost/myapp?useUnicode=yes&characterEncoding=UTF-8" username = "test" password = "test" dialect = org.hibernate.dialect.MySQL5InnoDBDialect properties { validationQuery = "select 1" testWhileIdle = true