Last active
May 27, 2016 14:03
-
-
Save wmacgyver/3ec050cd024a5ed8787716ecd9852a80 to your computer and use it in GitHub Desktop.
standalong GORM script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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