Skip to content

Instantly share code, notes, and snippets.

@wmacgyver
Last active May 27, 2016 14:03
Show Gist options
  • Save wmacgyver/3ec050cd024a5ed8787716ecd9852a80 to your computer and use it in GitHub Desktop.
Save wmacgyver/3ec050cd024a5ed8787716ecd9852a80 to your computer and use it in GitHub Desktop.
standalong GORM script
import grails.persistence.*
import grails.orm.bootstrap.*
import org.h2.Driver
import org.springframework.jdbc.datasource.DriverManagerDataSource
def dataSource = new DriverManagerDataSource("jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE", 'sa', '')
dataSource.setDriverClassName(Driver.name)
def initializer = new HibernateDatastoreSpringInitializer(['hibernate.log_sql':'true'], Person)
def applicationContext = initializer.configureForDataSource(dataSource)
Person.withNewSession {
def person = new Person(firstName: 'John', lastName: 'Doe').save()
println person.count()
}
@Entity
class Person {
String firstName
String lastName
static constraints = {
firstName blank:false
lastName blank:false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment