-
-
Save graemerocher/c25ec929d9bcd1adcbea to your computer and use it in GitHub Desktop.
GORM for Hibernate in Groovy 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
@Grab("org.grails:grails-datastore-gorm-hibernate4:3.0.0.RELEASE") | |
@Grab("org.grails:grails-spring:2.3.6") | |
@Grab("com.h2database:h2:1.3.164") | |
import grails.orm.bootstrap.* | |
import grails.persistence.* | |
import org.springframework.jdbc.datasource.DriverManagerDataSource | |
import org.h2.Driver | |
init = new HibernateDatastoreSpringInitializer(Person) | |
def dataSource = new DriverManagerDataSource(Driver.name, "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE", 'sa', '') | |
init.configureForDataSource(dataSource) | |
println "Total people = " + Person.count() | |
@Entity | |
class Person { | |
String name | |
static constraints = { | |
name blank:false | |
} | |
} |
There is quite a number of failures with this if trying to use it with 5.0.0.M1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, it works like we have in this script, but if I increment a little bit the example something does not work as expected, example, the GORM does not inject addTo method to the class, see
@entity
class Person {
String name
Profile profile
}
@entity
class Profile {
String name
}
@entity
class Contacts {
static belongsTo = [person: Person]
String name
}
Profile profile = new Profile(name: "Profile1")
profile.save(flush: true)
Person p = new Person(name: "RODRIGO", profile: profile)
p.addToContacts(name: "contact1")
if(!p.save()){
puts p.errors
}
println "Total people = " + Person.count()
it reproduces the message : groovy.lang.MissingMethodException: No signature of method: Person.addToContacts() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:contact1]]
Possible solutions: getContacts()
See? is there any workaround?