gorm

StaleObjectStateException on one domain object in a list affects all remaining updates

喜欢而已 提交于 2019-12-12 01:55:37
问题 I have a Quartz job in Grails that iterates my users and do a nightly update on each user. However, if I get a StaleObjectStateException on an update of a user object, it seems every update after that gets the same StaleObjectStateException. Something like this: def users = User.list() users.each { user -> try { user.doUpdate() user.save() } catch (all) { // I end up here for every user object after a StaleObjectStateException } } How can I recover? I don't mind sporadic failures (ideally I

How to use createCriteria for many-to-many relation in Grails?

天涯浪子 提交于 2019-12-12 01:53:57
问题 I have domain classes as below: class Account { String name String uniqueName static hasMany = [roles:Role] } class Role { String name static belongsTo = [account:Account] static hasMany = [users: User] } class User { String name } I received Account's uniqueName from params.uniqueName. And I want to find all users list that has roles that belongsTo account. I want to use criteria() because I want to do it in pagination. I try like below code, it's work but it can't do a pagination. def

Grails - Trying to remove objects, but they come back

家住魔仙堡 提交于 2019-12-12 01:06:32
问题 I have two domain classes, Job and Description, in a simple one to many relationship: Job.groovy class Job { static hasMany = [descriptions: Description] static mapping = { descriptions lazy: false } } Description.groovy class Description { static belongsTo = [job: Job] } I have two controller actions: def removeDescriptionFromJob(Long id) { def jobInstance = Job.get(id) System.out.println("before remove: " + jobInstance.descriptions.toString()) def description = jobInstance.descriptions.find

Find all objects with value in list

匆匆过客 提交于 2019-12-12 00:57:22
问题 I'm introducing myself to the Grails environment (It's awesome ). I've been reaping the benefits of dynamically generated methods like the findAllBy* range. However, I've come to a problem and I'm unsure about how to proceed. An hour spent on Google didn't yield all that much for me either. Problem I have a class like the following: class Runner { static hasMany = [owners: Owner] } And in my Owner controller, I wish to find all Runner objects, that contain a given Owner . Effectively, I'm

Spring Boot + Hibernate + Grails ignores ddlAuto in yml file

点点圈 提交于 2019-12-11 23:56:57
问题 I don't want Hibernate to recreate or update the database schema. According to the documentation, you need to have this in your application.yml file: spring.jpa.hibernate.ddl-auto: none It doesn't work. Here's my application.yml file: spring: profiles.active: default spring.jpa.hibernate.ddl-auto: none --- spring: profiles: default spring.datasource: driverClassName: net.sourceforge.jtds.jdbc.Driver url: jdbc:jtds:sqlserver://IP/DB username: user password: password spring.jpa: hibernate:

Grails GORM sort by CASE statement

半腔热情 提交于 2019-12-11 22:46:11
问题 I'm trying to use a CASE statement to order by GORM query. What I have is a view with a column of state the value there can be a state abbreviation or the word General . I will run the query like this Dropdown.findByStateInList(['General','CA'], [sort: "stateOrderBy", order: "asc"] but it returns an error of could not resolve property: stateOrderBy of: workspace.Dropdown When I create my domain class like below the value of stateOrderBy is the string CASE WHEN state = 'General' THEN 2 ELSE 1

Hibernate Lazy Loading Proxy - GORM Static Api's `instanceOf` throws ClassCastException [duplicate]

China☆狼群 提交于 2019-12-11 21:06:02
问题 This question already has an answer here : Javassist Enhancement Fails on Deployment (1 answer) Closed 5 years ago . I am refactoring legacy code of an existing System in groovy/grails. Instead of using .class.name to check for a class type, I want to use the proxy safe and more concise .instanceOf (although the long term goal is to get rid of those type checks entirely). EDIT 2014/10/07: The shift to the static instanceOf method is not only for more concise code; this is about not having to

Using Grails + PostgreSQL - How do i debug the GORM?

落爺英雄遲暮 提交于 2019-12-11 19:26:14
问题 I am having an issue with PostgreSQL, while using Grails/GORM. I want to be able to figure out what the query is that is running. It is failing asking about a field that I do not have in the class, and I can not find in the db either, so I am wondering how to debug this. Here is my exception: ERROR: column this_.level_version does not exist Position: 123. Stacktrace follows: org.postgresql.util.PSQLException: ERROR: column this_.level_version does not exist Position: 123 at org.postgresql

How to iterate over a list in groovy and add property for each object

瘦欲@ 提交于 2019-12-11 18:09:58
问题 I have a list of events like so: events = Events.all Events have a many-to-many relationship with Users via class UserEvents modeled after the approach from spring-security-plugin: I would like to find out whether a User is attending an Event and I can do that by running this: UserEvent.get(currentUserId, eventId) Question How can I do this over all the elements of my list events so that in my view layer I can easily find out whether currentUserId is going to the event? 回答1: You can query for

Unidirectional one to many, and mapped by in Grails - can't get the integration test to pass

我的未来我决定 提交于 2019-12-11 17:45:08
问题 This has now been raised as a new query after all my explorations today which I believe is a defect - please read the newer post first. I have an RootEntity domain class and an EntityRelationship entity (I have separate explicit entity here as I want the relationship to have attributes of its own. I want two collections of unidirectional links from RootEntity to EntityRelationship like this A --references --> link (+attribs) --referenced by --> B Code: abstract class RootEntity { Long id