Thursday, August 12, 2010

Hibernate JPA 2.0 on glassfish v3 with Netbeans IDE setup tutorial

After it took me almost a day to get Hibernate working properly on GF I thought I'd write here how it's done.

In this tutorial I used the following products:
  • NetBeans 6.9.1 - get the JEE version at least
  • Glassfish 3.0.1
  • Mysql
and libraries:
  • Hibernate 3.5.3
  • Slf4j-1.5.8 (you need to get the same version as the API module distributed with hibernate - in this case  slf4j-api-1.5.8.jar)
  • Log4j 1.2.16
  • mysql-connector-java-5.1.11-bin.jar - this is used in GF to connect to MySQL databases.
Make sure you get all of the above before proceding.
From now on I'll assume you have NetBeans, Glassfish & MySql installed and working properly.

Creating a database
Use the following sql dump to create a test database:

SQLyog Ultimate v8.3 
MySQL - 5.0.77 : Database - tutorial

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

CREATE DATABASE /*!32312 IF NOT EXISTS*/`tutorial` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `tutorial`;

/*Table structure for table `employee` */


CREATE TABLE `employee` (
  `employeeId` int(11) NOT NULL auto_increment,
  `employeeName` varchar(100) default NULL,
  PRIMARY KEY  (`employeeId`)

/*Data for the table `employee` */

insert  into `employee`(`employeeId`,`employeeName`) values (1,'John Doe'),(2,'Frank Bates'),(3,'Alex Smith');


Also, don't forget to create a user with full access to this DB.

Friday, December 11, 2009

Integrating Google Web Toolkit (GWT 2.0) with CodeIgniter

Integrating GWT with a php framework can be a little tricky since there isn't much documentation on the web on the subject.

First of all you will need two projects:
- one for the CodeIgniter server side PHP application
- one for the Java GWT client application

These are the main steps needed to setup GWT with CI.

1) Setup CodeIgniter configuration:
- change in "config.php" the following setttings:

$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;

These are required only in development mode to allow GET variables in url . For production use you can revert to your original settings.

2) Setup the host view
Normally GWT starts up from a "host" html file, but in CI this needs to be done from inside a view.
Let's assume that "gwthost.php" is the view file where you want to display the GWT Application:

<!-- the rest of your HTML here -->

<script type="text/javascript" language="javascript"

<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1'

<!-- we define a place where the GWT App will show up -->
<div id = "gwt_container"> </div>

GWT_MODULE is the name of the module you'll create for your GWT Project (step 3)

You will load the view as usual from a controller function:
/* controller test.php */

function showGWT(){

3) In this step we will configure the GWT Application to run without the built in server.

I assume you successfully installed GWT SDK 2.0 and Eclipse plugin and that you are able to compile and run the included samples. Please refer to the official google docs for reference.

  • Open or create a GWT project in Eclipse

  • first setup the compile path:

  • Click the "GWT Compile Project" button, then in the Advanced section, Additional compiler arguments enter:


    PATH_TO_SERVER_APP is the file system path for server application (web server folder), for example:

    -war d:\xampp\htdocs\gwttest

  • Click Compile

  • At this point, if the web server is started you should be able to access your application from a browser (http://localhost/gwttest/test/showgwt )

    remember the test.php controller ;)

    At this point we configured gwt to run in "web mode". You need to recompile the project after each modification.

    To enable "dev mode" follow the next step:
  • Open the "Run Configurations" for your project

  • In Main tab, disable "Run built-in server"

  • Go to "Arguments" tab and enter the following parameter:

  • -startupUrl http://CI_PAGE_URL


    -startupUrl http://localhost/gwttest/test/showgwt

    If you run this configuration it will prompt you to use an url like this one:

Paste this in your browser and it will prompt you to install the GWT Plugin and you should be running in "dev mode".
This means that if you change the source code you don't have to recompile the GWT application; just refresh the browser.