grails-domain-class

Mapping two domain classes in Grails

随声附和 提交于 2019-12-10 11:49:20
问题 I have two tables in our database that need mapped. The first is a Student table. It looks something like this: id first_name last_name major_code_1 major_code_2 And the Major table is like this: id description I need to map the major codes of the student, where major_code_1 and major_code_2 point to an id in the Major table. How could I do this? Thanks! 回答1: Here is a simple model which maps to your schema: class Student { String firstName String lastName Major firstMajor Major secondMajor

How to access Grails domain classes in Java service layer?

て烟熏妆下的殇ゞ 提交于 2019-12-09 01:38:05
问题 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

Grails 3.1.0.M2 Database Reverse Engineering

你。 提交于 2019-12-08 23:11:30
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. 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. Since the plugin is only used at build time, and often only once or at most a few times, I recommend that you

Grails domain class creation from database

可紊 提交于 2019-12-08 02:22:01
问题 I would like to create grails domain classes from an existing database, normally i was creating database from domain classes now i need to create it from an existing database schema. Please help me if there is any command available for that. 回答1: I'm on the same problem and I've found this Grails plugin: http://grails-plugins.github.com/grails-db-reverse-engineer/docs/manual/guide/single.html. It works perfectly: it inspects the existent database and creates domain classes, all ready to go.

belongsTo multiple Domain

醉酒当歌 提交于 2019-12-06 13:40:32
问题 I have 4 classes, incidents,problems, requests and another is Attachment. Every domain look like......... Class Incidents { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Problems { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Requests { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Attachment {

Grails domain class creation from database

拟墨画扇 提交于 2019-12-06 11:38:51
I would like to create grails domain classes from an existing database, normally i was creating database from domain classes now i need to create it from an existing database schema. Please help me if there is any command available for that. I'm on the same problem and I've found this Grails plugin: http://grails-plugins.github.com/grails-db-reverse-engineer/docs/manual/guide/single.html . It works perfectly: it inspects the existent database and creates domain classes, all ready to go. Just follow the steps showed in the example and you're done. There is a tool called GRAG: http://grag

How to override the DomainClass.list() in GORM (Grails)

点点圈 提交于 2019-12-06 08:11:20
问题 People, I'm facing a problem with grails GORM , my Application is totally dependent of the DomainClass.list() method, it is in all of my create/edit GSPs, but now I need a particular behavior for listing objects. Being more specific I need to filter these lists (All of them) by one attribute. The problem is I'm hoping not to change all the appearances of these methods calling, so is there a way to customize the behavior of the default list() method ? I need it to function just the way it does

Grails custom validator for domain class

China☆狼群 提交于 2019-12-06 08:01:27
问题 I have a restriction so there could be no more than ConfigurationHolder.config.support.reminder.web.person.max object stored. I didn't find how to add a validator which doesn't relate on particular property. So for now I implemented it in this way. Do you guys have any ideas how to make it better? package support.reminder.web import org.codehaus.groovy.grails.commons.ConfigurationHolder; class Person { String firstName String lastName String email Date lastDutyDate static constraints = {

How to set formula in grails domain class?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:06:53
I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i.e. can not resolve property 'ddmmyy' of 'myClass'. MyCriteria is: Date myDate = Calender.instance.time

Grails 2.4.2 - Dynamically referencing default datasource

ⅰ亾dé卋堺 提交于 2019-12-06 05:19:18
问题 This question has been partly answered here but there is still an issue with referencing the default datasource dynamically. I'm working on an internal application that allows developers to modify configuration settings for one of our multi-tenant applications and push those settings from dev to testing, staging and production. Each one of these will have their own datasource, and the Grails app will be installed on each developer's computer. The local datasource will be the default one, and