gorm

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

Importing domain classes from GORM-standalone module into Grails

三世轮回 提交于 2019-12-20 07:15:40
问题 I have 2 pieces of my puzzle: 1) a no-Grails project named core-module with standalone GORM: dependencies { compile 'org.grails:grails-datastore-gorm-mongodb:6.0.4.RELEASE' compile 'org.grails:grails-validation:3.2.3' } and domain classes like: import grails.gorm.annotation.Entity @Entity class Module { String id String tags } the GORM-ing is initialized by Map config = new Yaml().load this.class.getResource( '/application.yml' ).text new MongoDatastore( config, Module, UserAccount ) and the

Average of subquery in GORM

穿精又带淫゛_ 提交于 2019-12-20 06:24:29
问题 I have a table T with columns A & C, from which I would like to retrieve an average count like so: select avg(AC) as AV from ( select A, count(1) as AC from T where C = 1 group by A ) How do I accomplish this in GORM? GRAILS version 2.2.0 I tried following the documentation but there are no good examples. I couldn't even get the subquery to work :( Update I was able to get the count portion to work. Still now sure how to get the average since I don't know how to select from a query. def tc =

Count one-to-one relationship in grails

牧云@^-^@ 提交于 2019-12-20 05:47:19
问题 I have a problem doing a query. That I want to do is access with a query to the data in my "String code" in MyDomainA through a query from MyDomainB. The relationship between the tables is unidirectional one to one. Is possible use a gorm way to do this?? Domain A: class LicenceType { String code String description Double price static constraints = { } } TABLE DOMAIN A code description A this is A B this is B C this is C Domain B: (have the unidirectional relationship) class VoiceUser {

Grails GORM : SELECT AS

北城余情 提交于 2019-12-20 04:38:35
问题 I'm trying to get all the Users that are born today with GORM but I'm failing to write this query in Grails: SELECT DAY(dateOfBirth) AS 'day', MONTH(dateOfBirth) AS 'month' FROM Users WHERE day = '...' AND month = '...'; ... will be replaced with today's values. Minimal User Domain class class User { Date dateOfBirth ... } Minimal UserService class @Transactional class UserService { def getTodayBirthdays() { def bornTodayQuery = User.where{ /* I'm thinking here I must * select the DAY and

Grails criteria query checking `OR` logic

拜拜、爱过 提交于 2019-12-20 04:23:32
问题 I having grails criteriaQuery where I am checking OR logic againist a single state variable like this: or { eq("status", Status.ONE) eq("status", Status.TWO) eq("status", Status.THREE) } This code is working fine, My question is, as I am checking OR logic againist a single state, Is there any way to optimize this code like eq("status",Status.ONE || Status.TWO || Status.THREE) Thanks in advance. 回答1: You can use 'in'( "status", [Status.ONE, Status.TWO, Status.THREE] ) Or just 'in'( "status",

How to know if a transactional method in a grails service was successful?

让人想犯罪 __ 提交于 2019-12-20 03:49:09
问题 I have something like this: class SomeService { static transactional = true def someMethod(){ ... a.save() .... b.save() .... c.save() .... etc... } } I want to know if the transactional method was successful or not, I don't want to check the error property in each domain object because the logic involve many domain classes and it would be difficult. 回答1: Use a.save(failOnError: true) b.save(failOnError: true) c.save(failOnError: true) d.save(failOnError: true) I'm assuming what you want is

Unable to set NamingStrategy using Spring Boot + GORM + Gradle

故事扮演 提交于 2019-12-20 03:49:07
问题 We're starting a new project using Spring Boot with GORM and Gradle. I've been able to configure most properties for hibernate, but I have so far been unable to find the correct way to set the naming strategy . Attempts I've tried setting a variety of properties in application.properties and adding the file hibernate.properties . We're using auto-configuration, and I see props are discovered and added in HibernateGormAutoConfiguration . I've also made some attempts creating the entity manager

Derived Properties using aggregate functions in Grails

自闭症网瘾萝莉.ら 提交于 2019-12-20 03:09:43
问题 I'm trying to create derived properties based on contained objects. Example below: class Generation { String name DateTime productionStart DateTime productionEnd static belongsTo = [line: Line] static hasMany = [bodyStyles: BodyStyle, engines: Engine, models: Model] static constraints = { line nullable: false name nullable: false, unique: ['line'], maxSize: 255, blank: false } static mapping = { // I've tried but this solution causes errors productionStart formula: 'MIN(engines

Override getter and setter in grails domain class for relation

前提是你 提交于 2019-12-19 06:45:35
问题 How to override getter and setter for field being a relation one-to-many in grails domain class? I know how to override getters and setters for fields being an single Object, but I have problem with Collections. Here is my case: I have Entity domain class, which has many titles. Now I would like to override getter for titles to get only titles with flag isActive equals true. I've tried something like that but it's not working: class Entity { static hasMany = [ titles: Title ] public Set<Title