gorm

configure grails to create the database if it doesn't exist.

∥☆過路亽.° 提交于 2019-12-11 03:35:31
问题 I have the following settings on a new grails project: dataSource { pooled = true driverClassName = "com.mysql.jdbc.Driver" dialect = "org.hibernate.dialect.MySQL5InnoDBDialect" username = "sa" password = "" } environments { development { dataSource { dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', '' url = "jdbc:mysql://localhost/myapp?useUnicode=yes&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8" username = "root" password = "" } } } when I run

The use of join in Grails GORM queries

≡放荡痞女 提交于 2019-12-11 02:38:35
问题 In Grails we define domain classes in such a way that clearly indicates the relationship between domain classes such as one to many or belongsTo (if any). Since Grails is based on DRY, does that mean we do not need to use the join keyword when performing complex HQL queries in Grails DomainClass.ExecuteQuery method? 回答1: Grails doesn't change the way you write your HQL it is the same whether your using Grails domain classes or POJO's. If you need to write queries that navigate the object

Grails calculated field in SQL

北城以北 提交于 2019-12-11 02:28:02
问题 I have a domain class InvoiceLine { String itemName BigDecimal unitCost Integer quantity } } I would like to come up with a grails closure using .withCriteria that does an aggregation of the (unitCost * quantity) so that I end up with sql select item_name, sum(unit_cost * quantity) from invoice_line group by item_name; For now, the best I could come up with is def result = InvoiceLine.withCriteria { projections { groupProperty('itemName') sum ('quantity * unitCost') } } Unfortunately, grails

Grails GORM integer validation

♀尐吖头ヾ 提交于 2019-12-11 01:49:09
问题 Environment: Grails 2.0.4, Java 1.6.0 I'd like to put a constraint on a Domain Object value requiring an integer value to prevent a decimal value from being entered. Entering 3.3 in the view results in the object being created with a value of 3. I was hoping for a validation error that would be kicked back to the user indicating only integer values are valid. class ADomainObject { Integer anInteger } Controller def save() { // Note: params["anInteger"] = "3.3" ADomainObject aDomainObject =

HQL Inner join on same table

余生长醉 提交于 2019-12-11 00:19:38
问题 I asked an earlier question today which was about GORM: How to fetch records in grails by max date and group at same time However, someone suggested it can be easily achieved using HQL. But using HQL I'm getting unexpected token error. When I researched this I found out that HQL doesn't allow INNER JOINS unless there is an association between two entities: HQL, left join on the same table So, I'm lost. To begin with, I'm frustrated why such a simple query isn't supported by GORM and now with

GORM Mapping two attributes of same Class with hasMany

依然范特西╮ 提交于 2019-12-10 23:49:22
问题 I have the following: class Match{ Team localTeam Team visitingTeam } class Team{ static hasMany = [matches: Match] } that throws: Error loading plugin manager: Property [matches] in class [class myapp.Team] is a bidirectional one-to-many with two possible properties on the inverse side. Either name one of the properties on other side of the relationship [team] or use the 'mappedBy' static to define the property that the relationship is mapped with. Example: static mappedBy = [matches:'myprop

How to import domain classes from jar into a Micronaut project?

与世无争的帅哥 提交于 2019-12-10 23:09:22
问题 I have a Micronaut project configured to use GORM and Groovy (1). This project contains lots of domain classes that are working perfectly, persisting data in a MySQL database as expected. Now I wish to make this domain classes common to another Micronaut project (2). I tried building a JAR file containing only the domain package and including it in the project 2 thru build.gradle . The classes are compiled and made accessible in code, and I'm able to call GORM methods like findBy ,

Querying computed fields in GORM

一曲冷凌霜 提交于 2019-12-10 21:34:47
问题 I am trying to query the following HQL using GORM: MailMessage.executeQuery("toId, count(toId) from (SELECT toId, threadId FROM MailMessage as m WHERE receiveStatus = 'u' GROUP BY threadId, toId) as x group by x.toId") The problem is that count(toId) is a computed field doesn't exist in MailMessage and that I am using a subquery. I get the following error: java.lang.IllegalArgumentException: node to traverse cannot be null! Ideally, I would like to use a generic executeQuery which will return

Grails as single app or different back-end and front end app [closed]

孤街浪徒 提交于 2019-12-10 21:32:39
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . We are new to grails and are concerned about the following issues: scalability concerns Using same back-end for different applications So sticking to a single grails is good idea or we should separate concerns and even use other framework like node.js for frontend using rest.

GORM refresh() method not getting latest data from database

萝らか妹 提交于 2019-12-10 20:56:34
问题 After saving a changed user name (using flush:true ), the following expression evaluates to false: User.get(u.getId()).name == u.refresh().name The left hand side picks up the changed user name while the right hand side return the "old" value. Ideas? Refreshing the "u" reference in the next HTTP request appears to work. 回答1: Is this being done within a transaction? If your code is executing within a transaction then even using flush: true won't immediately persist changes to the database.