Combining Groovy, Grails, MySQL, and the Java Persistence API (Carol McDonald)
Carol McDonald, Glassfish, Grails, JPA, MySQL, NetBeans July 31st, 2008
Carol McDonald has written an excellent article describing how to get a Grails application running based on Sun’s open source technology stack, MySQL in the database end, Glassfish v2 as the server engine, NetBeans 6.1 as the IDE of choice. JPA is also thrown into the mix as the EnterpriseTips site is all about JEE related topics.
With the addition of support for scripting languages in the Java platform, there has been a lot of interest in combining into web applications scripting languages such as Groovy, Java technologies such as the Java Persistence API (JPA), and databases such as MySQL. Last year I wrote a Tech Tip titled Combining JavaServer Faces Technology, Spring, and the Java Persistence API that showed how you can use JavaServer Faces Technology, Spring, and the JPA to create an application that displays an online catalog of pets. In this tip, I’ll show you how to create an online catalog application using the Groovy language, the Grails framework, the MySQL database, and the Java Persistence API.
A package that contains the code for the sample application accompanies the tip. The code examples in the tip are taken from the source code of the sample (which is included in the package). In this tip, you’ll use NetBeans IDE 6.5 Milestone 1 to build the application and deploy it on the GlassFish application server. The NetBeans IDE is a modular, standards-based, integrated development environment (IDE) written in the Java programming language. The latest NetBeans IDE offering, NetBeans IDE 6.5 Milestone 1 (or M1 for short), offers many new features including support for Groovy and Grails. GlassFish is a free, open source application server that implements the newest features in the Java EE 5 platform.
A Summary of the Languages, Technologies, and Frameworks in the Sample Application
If you’re not familiar with Groovy, Grails, MySQL, or the Java Persistence API, here are brief descriptions:
- Groovy is an agile and dynamic language for the Java Virtual Machine1. It compiles to Java bytecode and combines popular features from languages such as Smalltalk, Python, and Ruby.
- Grails is an open-source web application framework that leverages the Groovy language and complements Java Web development. It aims to bring the “coding by convention” paradigm to Groovy. Grails is a Model-View-Controller based framework that simplifies the development of web applications by reducing the need for configuration files and by generating a lot of the things needed in a database-backed web application.
- MySQL is the world’s most popular open-source database. It offers consistently fast performance, high reliability and ease of use.
- The Java Persistence API provides a (plain old Java object) POJO-based persistence model for Java EE and Java SE applications. It handles the details of how relational data is mapped to Java objects, and it standardizes Object/Relational (O/R) mapping.
The Sample Application
The sample application displays an online catalog of pets sold in a pet store. Figure 1 shows the Catalog Listing page, which allows a user to page through a list of items in a store.
The article is well balanced, you will find references to common Grails artifacts as controllers, domain classes and views. Carol also shows how the datasource must be configured and the steps you must follow to get the application running. Continue reading the whole article at this link.
Tags: Carol McDonald, Glassfish, Grails, JPA, MySQL, NetBeans


About