Skip to content

Instantly share code, notes, and snippets.

@graemerocher
Created April 4, 2014 08:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save graemerocher/9970349 to your computer and use it in GitHub Desktop.
Save graemerocher/9970349 to your computer and use it in GitHub Desktop.
Using GORM for Hibernate 4 in Spring Boot
@Grab("org.grails:gorm-hibernate4-spring-boot:1.0.0.RC2")
@Grab("com.h2database:h2:1.3.173")
import grails.persistence.*
import org.springframework.http.*
import static org.springframework.web.bind.annotation.RequestMethod.*
@RestController
class GreetingController {
@RequestMapping(value="/person/greet", method = GET)
String greet(String firstName) {
def p = Person.findByFirstName(firstName)
return p ? "Hello ${p.firstName}!" : "Person not found"
}
@RequestMapping(value = '/person/add', method = POST)
ResponseEntity addPerson(String firstName) {
Person.withTransaction {
def p = new Person(firstName: firstName).save()
return new ResponseEntity( p ? HttpStatus.CREATED : HttpStatus.BAD_REQUEST)
}
}
}
@Entity
class Person {
String firstName
}
@tagama
Copy link

tagama commented Jun 20, 2015

Hi Graeme!
Call me dumb, but should ResponseEntity, HttpStatus be with[In]Transaction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment