JavaEE 5 (JSF + JPA + EJB3) using Eclipse

Today I will show you how to create Enterprise Application using Java EE 5 and GlassFish.I will use – Eclipse 3.5 + WTP– GlassFish v. 2.1– JSF Mojarra implementation.– EJB 3.0.– JPA Toplink essentials implementation.– MySQLNo NetBeans or JDeveloper magic involved πŸ™‚The prerequirement is:Add datasource in glassfish. Read this how you can make this here: http://gochev.blogspot.com/2009/10/creating-datasource-in-glassfish-v-21.html 1) First you need to add glassfish in your eclipse.– Go to Servers View– Right Click, New– Choose GlassFish v 2.1 if you dont have glassfish click on Download additional adapters link choose glassfish wait and restart eclipse. Than try again.2) Create the database CREATE TABLE `lesson`.`USERS` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `username` VARCHAR(45) NOT NULL, `password` VARCHAR(45) NOT NULL, `name` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`))ENGINE = InnoDB; 3) Create EJB project 4) Add persistance.xml file in META-INF folder <?xml version="1.0" encoding="UTF-8"?><persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <persistence-unit name="toursUnit"> <jta-data-source>lessonMySQL</jta-data-source> <class>org.joke.model.User</class> </persistence-unit></persistence> 5) Create Simple Entity org.joke.model.User package org.joke.model;import javax.persistence.Basic;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.Table;@Entity@Table(name = "USERS")public class User { private Long id; private String name; private String username; private String password; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Basic public String getName() { return name; } public void setName(String name) { this.name = name; } @Basic public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Basic public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } 6) Create HelloService EJB that will use EntityManager – The local interface is: package org.joke.service;import javax.ejb.Local;import org.joke.model.User;@Localpublic interface...

JavaEE 5 (JSF + JPA + EJB3) using Eclipse

Today I will show you how to create Enterprise Application using Java EE 5 and GlassFish.I will use – Eclipse 3.5 + WTP– GlassFish v. 2.1– JSF Mojarra implementation.– EJB 3.0.– JPA Toplink essentials implementation.– MySQLNo NetBeans or JDeveloper magic involved πŸ™‚The prerequirement is:Add datasource in glassfish. Read this how you can make this here: http://gochev.blogspot.com/2009/10/creating-datasource-in-glassfish-v-21.html 1) First you need to add glassfish in your eclipse.– Go to Servers View– Right Click, New– Choose GlassFish v 2.1 if you dont have glassfish click on Download additional adapters link choose glassfish wait and restart eclipse. Than try again.2) Create the database CREATE TABLE `lesson`.`USERS` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `username` VARCHAR(45) NOT NULL, `password` VARCHAR(45) NOT NULL, `name` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`))ENGINE = InnoDB; 3) Create EJB project 4) Add persistance.xml file in META-INF folder <?xml version="1.0" encoding="UTF-8"?><persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <persistence-unit name="toursUnit"> <jta-data-source>lessonMySQL</jta-data-source> <class>org.joke.model.User</class> </persistence-unit></persistence> 5) Create Simple Entity org.joke.model.User package org.joke.model;import javax.persistence.Basic;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.Table;@Entity@Table(name = "USERS")public class User { private Long id; private String name; private String username; private String password; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Basic public String getName() { return name; } public void setName(String name) { this.name = name; } @Basic public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Basic public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } 6) Create HelloService EJB that will use EntityManager – The local interface is: package org.joke.service;import javax.ejb.Local;import org.joke.model.User;@Localpublic interface...

Creating DataSource in GlassFish v. 2.1

I will show you how to create a DataSource in GlassFish version 2.1 because there were a lot of properties and I had a lot of problems when I’ve try to register datasource in glassfish for the first time. 1) You have to download JDBC driver for your database. For example I will use MySQL and I will use Connector/J driver that you can download from mysql official web site. 2) Place the JDBC driver in for example D:glassfishv21domainsdomain1libext for example my driver is mysql-connector-java-5.0.4.jar 3) Start the domain for example domain1 (asadmin start-domain domain1) 4) go to http://localhost:4848 and login as admin. By default the username is ‘admin’ and the password is ‘adminadmin’ 5) go to Resources/JDBC/Connection Pools -First we will create a connection pool. Click the ‘NEW’ button -Than you must type: – Name: of the connection pool for example MySQL Lessson – Resource Type: javax.sql.ConnectionPoolDataSource – Database Vendor: MySQL -Press ‘Next’-On the Next step scroll down you will see a list of properties. The important for you (you must select this checkboxes) are: ‘user’,’password’,’url’. If some of this is missing for example there is no ‘url’ if the vendor is Oracle you can add it using the Add property button. – user : root – password : rootpassword – url : jdbc:mysql://localhost:3306/lesson?autoReconnect=true&characterEncoding=utf8 -When you fill this 3 properties you must press ‘Save’ -Than select again your datasource and press ‘Ping’ to see is everything correct You are now ready to create your DataSource that will use this connection pool. 6)go to Resources/JDBC/JDBC Resources – Press ‘New’– Type some jndi name of the resource that you will...

Creating DataSource in GlassFish v. 2.1

I will show you how to create a DataSource in GlassFish version 2.1 because there were a lot of properties and I had a lot of problems when I’ve try to register datasource in glassfish for the first time. 1) You have to download JDBC driver for your database. For example I will use MySQL and I will use Connector/J driver that you can download from mysql official web site. 2) Place the JDBC driver in for example D:glassfishv21domainsdomain1libext for example my driver is mysql-connector-java-5.0.4.jar 3) Start the domain for example domain1 (asadmin start-domain domain1) 4) go to http://localhost:4848 and login as admin. By default the username is ‘admin’ and the password is ‘adminadmin’ 5) go to Resources/JDBC/Connection Pools -First we will create a connection pool. Click the ‘NEW’ button -Than you must type: – Name: of the connection pool for example MySQL Lessson – Resource Type: javax.sql.ConnectionPoolDataSource – Database Vendor: MySQL -Press ‘Next’-On the Next step scroll down you will see a list of properties. The important for you (you must select this checkboxes) are: ‘user’,’password’,’url’. If some of this is missing for example there is no ‘url’ if the vendor is Oracle you can add it using the Add property button. – user : root – password : rootpassword – url : jdbc:mysql://localhost:3306/lesson?autoReconnect=true&characterEncoding=utf8 -When you fill this 3 properties you must press ‘Save’ -Than select again your datasource and press ‘Ping’ to see is everything correct You are now ready to create your DataSource that will use this connection pool. 6)go to Resources/JDBC/JDBC Resources – Press ‘New’– Type some jndi name of the resource that you will...

JavaEE 5 (JSF + JPA + EJB3) using Eclipse

Today I will show you how to create Enterprise Application using Java EE 5 and GlassFish.I will use – Eclipse 3.5 + WTP– GlassFish v. 2.1– JSF Mojarra implementation.– EJB 3.0.– JPA Toplink essentials implementation.– MySQLNo NetBeans or JDeveloper magic involved πŸ™‚The prerequirement is:Add datasource in glassfish. Read this how you can make this here: http://gochev.blogspot.com/2009/10/creating-datasource-in-glassfish-v-21.html 1) First you need to add glassfish in your eclipse.– Go to Servers View– Right Click, New– Choose GlassFish v 2.1 if you dont have glassfish click on Download additional adapters link choose glassfish wait and restart eclipse. Than try again.2) Create the database CREATE TABLE `lesson`.`USERS` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `username` VARCHAR(45) NOT NULL, `password` VARCHAR(45) NOT NULL, `name` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`))ENGINE = InnoDB; 3) Create EJB project 4) Add persistance.xml file in META-INF folder <?xml version="1.0" encoding="UTF-8"?><persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <persistence-unit name="toursUnit"> <jta-data-source>lessonMySQL</jta-data-source> <class>org.joke.model.User</class> </persistence-unit></persistence> 5) Create Simple Entity org.joke.model.User package org.joke.model;import javax.persistence.Basic;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.Table;@Entity@Table(name = "USERS")public class User { private Long id; private String name; private String username; private String password; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Basic public String getName() { return name; } public void setName(String name) { this.name = name; } @Basic public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Basic public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } 6) Create HelloService EJB that will use EntityManager – The local interface is: package org.joke.service;import javax.ejb.Local;import org.joke.model.User;@Localpublic interface...

Creating DataSource in GlassFish v. 2.1

I will show you how to create a DataSource in GlassFish version 2.1 because there were a lot of properties and I had a lot of problems when I’ve try to register datasource in glassfish for the first time. 1) You have to download JDBC driver for your database. For example I will use MySQL and I will use Connector/J driver that you can download from mysql official web site. 2) Place the JDBC driver in for example D:glassfishv21domainsdomain1libext for example my driver is mysql-connector-java-5.0.4.jar 3) Start the domain for example domain1 (asadmin start-domain domain1) 4) go to http://localhost:4848 and login as admin. By default the username is ‘admin’ and the password is ‘adminadmin’ 5) go to Resources/JDBC/Connection Pools -First we will create a connection pool. Click the ‘NEW’ button -Than you must type: – Name: of the connection pool for example MySQL Lessson – Resource Type: javax.sql.ConnectionPoolDataSource – Database Vendor: MySQL -Press ‘Next’-On the Next step scroll down you will see a list of properties. The important for you (you must select this checkboxes) are: ‘user’,’password’,’url’. If some of this is missing for example there is no ‘url’ if the vendor is Oracle you can add it using the Add property button. – user : root – password : rootpassword – url : jdbc:mysql://localhost:3306/lesson?autoReconnect=true&characterEncoding=utf8 -When you fill this 3 properties you must press ‘Save’ -Than select again your datasource and press ‘Ping’ to see is everything correct You are now ready to create your DataSource that will use this connection pool. 6)go to Resources/JDBC/JDBC Resources – Press ‘New’– Type some jndi name of the resource that you will...