grails-domain-class

equivalent of InheritanceType.TABLE_PER_CLASS in grails?

微笑、不失礼 提交于 2019-12-02 11:17:47
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? 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%20Inheritance%20Strategies Something I was trying to also achieve and yes it is possible with grails, it is a case

Grails get session variable from domain validator

為{幸葍}努か 提交于 2019-12-02 10:27:13
问题 Im sure this is a common scenario, but I haven't found any answers. I have a session-scoped variable that holds the currently signed in user and I need to perform conditional validation by way of a custom validator in a domain object. Is there a way to get the the current user from the session scope while in a validator, or is there perhaps another way to do this, keeping in mind that I want to be able to return the errors for specific fields from my validator(e.g. if(isBlank(it))return [

How to hide password fields from Grails scaffolding views?

﹥>﹥吖頭↗ 提交于 2019-12-02 09:33:06
According to the docs , Grails provides a number of constraints that "have no impact on persistence but customize the scaffolding". One of them is the password constraint. Here's how I use it: class User { String username String password static constraints = { username blank: false password blank: false, password: true } } In combination with scaffolding, this has the effect that the edit view uses a specialized password input for my password field (that's fine), but the index and show view still show the password in plain text (not fine at all). Is there a way to have the password field only

Grails: domain class mapping (collection of hibernate user types)

前提是你 提交于 2019-12-02 05:53:13
问题 I am wondering if is possible to implement following domain model. Let's have a domain class which contains set of intervals (joda time). I can use org.joda.time.contrib.hibernate.PersistentInterval hibernate user type for mapping of Interval to database table (by similar way as in http://www.grails.org/JodaTime+Plugin). However I cannot figure out how to implement mapping if I have set of intervals, not only one interval. Example: class Activity { ... Set intervals = [] ... static hasMany =

Grails - adding custom fields (columns) to all domain objects - automatically

限于喜欢 提交于 2019-12-02 05:47:19
问题 By default when you create a domain class, it will automatically add "id" and "version" column for all the domain classes (tables). What if I want to add a column say for e.g. "isChecked" and this should be added automatically to all the domain classes (i.e tables) similar way "id" and "version" columns are added. How can I achieve this and also if I don't want to have "isChecked" for a specific domain class, I should also be able to do that. How can I do this in Grail 1.3.7? Thank You. Jay

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

和自甴很熟 提交于 2019-12-01 22:35:07
When I do domainObj1 == domainObj2 in Grails are the objects compared by ID? If not, how are they compared? Joshua Moore 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 cache); when you fetch the same domain instance from GORM, Hibernate will actually return the same

Grails min constraint for date validation

爱⌒轻易说出口 提交于 2019-12-01 15:55:25
I am a newbie in grails and groovy. I have a Project domain-class with start and end date. I want to put in a constraint specifying that the end date needs to be greater than the start date(and then further another child object of project needs to have its startdate and enddate validate with the parent Project's dates). Is this possible with the min constraint or do I have to put it elsewhere? Unique constraint does allow two properties to be linked that way, hoping min/max constraints allow that. I have tried startDate(blank:false) endDate(blank:false, min:'startDate') It throws an error

Grails min constraint for date validation

流过昼夜 提交于 2019-12-01 14:39:57
问题 I am a newbie in grails and groovy. I have a Project domain-class with start and end date. I want to put in a constraint specifying that the end date needs to be greater than the start date(and then further another child object of project needs to have its startdate and enddate validate with the parent Project's dates). Is this possible with the min constraint or do I have to put it elsewhere? Unique constraint does allow two properties to be linked that way, hoping min/max constraints allow

How to access Grails domain classes in Java service layer?

懵懂的女人 提交于 2019-12-01 00:57:32
How can I use grails domain classes (which is in groovy) in service layer which is in Java/Spring. When using the grails MVC, everything is fine as I can use controller to access domain objects and call CRUD and other dynamic methods on them. But, what I am wondering is is there a clean way to do it from Java - say the service layer. For example, I may want to develop a reporting framework where I need to use domain objects to access the DB. I Hope the question is clear. This should be a standard problem that everybody must have faced in a reasonably sized project. I am just wondering how it

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

社会主义新天地 提交于 2019-11-30 13:46:43
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? MudDawg I ran into this question myself a couple of weeks ago. You can just add the following snippet to the Domain Class . def isAttached() { return false } Now it