gorm

How to cope with 'org.postgresql.util.PSQLException: No value specified for parameter 1'?

北战南征 提交于 2019-12-02 04:03:47
Upon registration to my Grails app, the user receives an email with a confirmation link. Clicking that link, takes her to the according 'enable' action. This worked flawlessly. However, there now seems to be an error with a very specific token, which fails the user.save() of this snippet: assert !user.isDirty() // assertion is ok user.enabled = true user.confirmationToken = null assert user.isDirty() // assertion is ok if (user.save()) { // FAILS WITH ERROR BELOW // ... } Stacktrace: [ 16.09.2011 11:57:47.591] [http-bio-localhost/127.0.0.1-8080-exec-3] ERROR org.codehaus.groovy.grails.web

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

烈酒焚心 提交于 2019-12-02 03:37:26
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. Use a.save(failOnError: true) b.save(failOnError: true) c.save(failOnError: true) d.save(failOnError: true) I'm assuming what you want is the service to throw exception on error of a single domain save, and rollback the transaction in such cases.

Common beforeInsert and beforeUpdate methods from Mixin for common domain columns

▼魔方 西西 提交于 2019-12-02 03:02:48
Most of the domain objects our company uses will have some common properties. These represent the user that created the object, the user that last updated the object, and the program they used to do it. In the interest of DRY ing out my domain classes, I want to find some way to add the same beforeInsert and beforeUpdate logic to all domain classes that have these columns without interfering with those that don't. How I'd like to do it is using a Mixin with its own beforeInsert and beforeUpdate methods. I know you can use Mixins on domain classes . package my.com import my.com.DomainMixin

gorm save method causing a select query to fire

岁酱吖の 提交于 2019-12-02 00:47:12
I am using grails 1.3.7 and zkoss and my domain model is as below, I load the Person entity in session 1 and make changes to it through the UI. The on press of save in session 2 I want to save the entity. So from my composer/controller I call a service method(transactional) and then do person.save(), When i see the sql queries being fired I see a query which tries to retrieve the employee object. After which the save is fired and throws a nonuniqueobjectexception Exception org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the

Derived Properties using aggregate functions in Grails

不羁岁月 提交于 2019-12-01 23:28:11
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.productionStart)' // I've tried but this solution causes errors productionEnd formula: 'MAX(engines.productionEnd)' }

Grails + GORM: What is the default equals() implementation in GORM?

和自甴很熟 提交于 2019-12-01 22:35:07
When I do domainObj1 == domainObj2 in Grails are the objects compared by ID? If not, how are they compared? Joshua Moore First, you need to understand that GORM/Grails doesn't do anything special when it comes to equals() . Unless you implement your own equals() on your domain class it will default to the Java/Groovy implementation. Which by default means the variables must point to the same instance. Now, what gets slightly confusing is Hibernate. Hibernate uses an identity map (the first-level cache); when you fetch the same domain instance from GORM, Hibernate will actually return the same

Does removing a property from a domain class cause an automatic update to the schema, whereby the corresponding column is dropped?

别等时光非礼了梦想. 提交于 2019-12-01 19:38:48
I'm sort of new at Grails. I've worked with it a bit, but not that much. I'm pretty familiar with Java though. My question is regarding schema updates. I understand that Grails creates Hibernate mappings by looking at the domain classes, and so if I add a new property, Grails will automatically add a column for that property in the database. Does the reverse also hold true? If I remove a property, is that column removed? I'm not seeing that behavior and so I'm wondering if it is a configuration issue. If I wanted to go into more robust database-management, I'm guessing I will have to use the

Grails 3.0.1 - how to configure grails.gorm.default.constraints in application.yml

廉价感情. 提交于 2019-12-01 17:18:22
问题 I took the old configuration: grails.gorm.default.constraints = { '*' (nullable: true, blank: true) } ... and put it in the application.groovy . Luckily it worked as expected. How would one define this in application.yml ? I tried: grails: gorm: default: constraints: '*' (nullable: true, blank: true) but this gives errors on start. 回答1: application.groovy is the place to do that. Groovy code in a .yml config file is invalid and not supported. 来源: https://stackoverflow.com/questions/29518459

Heroku Postgres: This connection has been closed

半世苍凉 提交于 2019-12-01 16:28:42
I developed a small Heroku + Grails + Postreg application. It would work fine somewhat 20 minutes after deployment, after that I always get: This connection has been closed.. Stacktrace follows: Heroku/myapp - org.postgresql.util.PSQLException: This connection has been closed. Heroku/myapp - at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:837) Heroku/myapp - at org.postgresql.jdbc2.AbstractJdbc2Connection.getAutoCommit(AbstractJdbc2Connection.java:798) Heroku/myapp - at org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2.doCall(GormStaticApi

Heroku Postgres: This connection has been closed

陌路散爱 提交于 2019-12-01 15:44:32
问题 I developed a small Heroku + Grails + Postreg application. It would work fine somewhat 20 minutes after deployment, after that I always get: This connection has been closed.. Stacktrace follows: Heroku/myapp - org.postgresql.util.PSQLException: This connection has been closed. Heroku/myapp - at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:837) Heroku/myapp - at org.postgresql.jdbc2.AbstractJdbc2Connection.getAutoCommit(AbstractJdbc2Connection.java:798)