Grails ConcurrentModificationException in custom eventlistener - grails

I have a Grails (2.4.3) application which uses a PersistenceListener to listen on GORM events.
The PersistenceListener works fine. In the PreUpdate event, it calls a service (injected) which does a findAll on a related object. Here, I am just gathering values to update a 3rd party system. The service doesn't change any object value at all including the event.entityObject.
It gets a ConcurrentModificationException after the PreUpdate is run and the instance.save is invoked on the controller.
If I remove/comment the findAll of the related object, the exception goes away.
I suspect this is to do with Hibernate. Related questions all talk about iterators and using their remove methods. Here I am not removing any values, just trying to get the related objects.

Are you on JDK 8 where even sort is also considered as a modification operation different from JDK 7 ?
This may not be an answer; but I had to write it as an answer since I don't have permission to comment. Please remove this if its not relevant.

Related

Resolving relations inside a chain transaction

I've tested the possibility of resolving the relations with the "composer-client" library. I see in the API reference that the "composer-client.AssetRegistry" class has "resolve" and "resolveAll" Methods from its super-class "Registry". The methods are useful when developing a client application.
However, the composer-runtime.AssetRegistry has only "get" and "getAll" methods, which return registry records without resolving the "relations".
I can't seem to find any way of resolving the relations inside the transaction code. Any clues on that? Thx.
You're right that the composer-runtime doesn't offer the resolve/resolveAll methods currently. Having said that, you may not need these functions since any objects that are passed as parameters to the transaction code should be fully resolved and so you should be able to access everything you need from the objects that you're passed.
I guess it depends on what your use case is really. If you're wanting to get assets from AssetRegistries independently from within your transaction code then you'll have to resolve the relationships manually, following the relationships using the runtime API as things currently stand.

Grails named queries as scroll results

I know that I can do Alert.Criteria().scroll() but I cannot seem to do it with named queries. Can it be done?
Right now, and it looks like this won't change, it is not possible to use scroll() with named queries. You can look at the Grails source code of the NamedQueryProxy (which is the actual instance you get back when calling a named query) at GitHub using this path:
grails-data-mapping/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/query/NamedQueriesBuilder.groovy
According to the Grails team, the named query feature has largely been replaced by where queries. There's some other problems with named queries (like when adding additional criteria at invocation, the query automatically executes .list() ). I opened two issues with the Grails team and it seems they will not be evolving the feature set and stability of named queries in favor of using where queries instead.

Sorting on a unknown property

I’m building a small application, and in part of the UI you can sort some objects (persons). So when I call this url:
http://localhost:8080/addressbook/person/list?sort=name
all works nicely.
However, when I change the URL to the following, my application is throwing exceptions:
http://localhost:8080/addressbook/person/list?sort=thisisanunknowproperty
I get errors like:
Class
org.hibernate.QueryException
Message
could not resolve property: thisisanunknownproperty of: persons.Person
This is really not what I want, of course. The application should just not sort, and not throw exceptions like this. But how do I prevent this behavior from happening?
Thing which come to mind is that I build something in which checks if the property is a member of the allowed properties to sort, but I'm wondering if there is anything out of the box for this which I missed?
As I mentioned via email, take a look at Grails Command Objects which are based around the Spring Validation API.
The hard and fast rule is never, ever blindly accept user input. In many frameworks, Grails included, this has exposed some nasty security holes.

How does Grails handle Database triggers?

I have an existing oracle database with triggers when a record is created. The documentation indicate to register evenlisteners for update and create. Do anybody know best practice.
What happens after or before the record is created when you use triggers is totally dependent of the db that you're using. As #aldrin says, it will help consistency if there's another application handling the same database.
I suggest you to use the events if there're plans to support more than one database vendor because you avoid the work to translate triggers between them.
If you are asking if Oracle triggers can be replicated in grails - the answer is that the event binding can be replicated (see http://grails.org/doc/latest/guide/GORM.html#eventsAutoTimestamping). as far as, what you are doing in PL/SQL for the trigger logic, that might not translate as easily.

Modifying a domain class after objects have already been persisted with that class

This question is similar to the question here.
Let us assume that I have made a Grails application and then, sometime down the road, I need to add a field to a domain class. What would be the best way to add that field and have all the objects already persisted to the database be updated too? Is there anyway to do this in Grails (currently using 1.3.7, but upgrading to 2.0 when it is stable) without manually accessing the database?
Use this plugin: http://grails.org/plugin/database-migration

Resources