This is a quickstart built upon kitchensink additionally demonstrating how to use Hibernate4 as ORM over JPA in AS7(or EAP6)!
+It's a sample, deployable Maven 3 project to help you
+get your foot in the door developing with Java EE 6 and Hibernate 4 on JBoss AS 7 or EAP 6. This
+project is setup to allow you to create a compliant Java EE 6 application
+using JSF 2.0, CDI 1.0, EJB 3.1, JPA 2.0 , Hibernate-Core and Hibernate Bean Validation.
+It includes a persistence unit associated with Hibernate session and some sample persistence and transaction code
+to help you get your feet wet with database access in enterprise Java.
+
System requirements
+
All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven
+3.0 or better.
+
The application this project produces is designed to be run on a JBoss AS 7 or EAP 6.
+The following instructions target JBoss AS 7, but they also apply to JBoss EAP 6.
+
With the prerequisites out of the way, you're ready to build and deploy.
+
Adding correct Dependencies
+
JBoss AS7 (or EAP 6) provides both JPA as well as Hibernate4(as ORM) and also supports Hibernate3 etc.
+If you choose to use Hibernate4 packaged within JBoss AS7(or EAP6) you will need to first import the JPA API.
+This quickstart demonstrates usage of Hibernate Session and Hibernate Validators.
+You will also need to add dependencies to the required Hibernate modules for using these features in pom.xml with scope as provided.
+for eg . check dependency for hibernate-validator in pom.xml
+
Please note that if you are working with Hibernate 3 the process is different as you will need to bundle the jars since JBoss AS7(or EAP6)
+does not ship with Hibernate 3.
+Please refer to the quickstart demonstrating Hibernate3 for details on how to bundle the jars in such cases.
+
Deploying the application
+
First you need to start JBoss AS 7 (or EAP 6). To do this, run
+
$JBOSS_HOME/bin/standalone.sh
+
+
or if you are using windows
+
$JBOSS_HOME/bin/standalone.bat
+
+
To deploy the application, you first need to produce the archive to deploy using
+the following Maven goal:
+
mvn package
+
+
You can now deploy the artifact to JBoss AS by executing the following command:
You can also start JBoss AS 7 and deploy the project using Eclipse. See the JBoss AS 7
+Getting Started Guide for Developers for more information.
+
Importing the project into an IDE
+
If you created the project using the Maven archetype wizard in your IDE
+(Eclipse, NetBeans or IntelliJ IDEA), then there is nothing to do. You should
+already have an IDE project.
+
Detailed instructions for using Eclipse with JBoss AS 7 are provided in the
+JBoss AS 7 Getting Started Guide for Developers.
+
If you created the project from the commandline using archetype:generate, then
+you need to import the project into your IDE. If you are using NetBeans 6.8 or
+IntelliJ IDEA 9, then all you have to do is open the project as an existing
+project. Both of these IDEs recognize Maven projects natively.
+
Downloading the sources and Javadocs
+
If you want to be able to debug into the source code or look at the Javadocs
+of any library in the project, you can run either of the following two
+commands to pull them into your local repository. The IDE should then detect
+them.
diff --git a/hibernate4/readme.md b/hibernate4/readme.md
new file mode 100644
index 0000000000..dc96b97e05
--- /dev/null
+++ b/hibernate4/readme.md
@@ -0,0 +1,111 @@
+hibernate4
+========================
+
+What is it?
+-----------
+
+This is a quickstart built upon kitchensink additionally demonstrating how to use Hibernate4 as ORM over JPA in AS7(or EAP6)!
+It's a sample, deployable Maven 3 project to help you
+get your foot in the door developing with Java EE 6 and Hibernate 4 on JBoss AS 7 or EAP 6. This
+project is setup to allow you to create a compliant Java EE 6 application
+using JSF 2.0, CDI 1.0, EJB 3.1, JPA 2.0 , Hibernate-Core and Hibernate Bean Validation.
+It includes a persistence unit associated with Hibernate session and some sample persistence and transaction code
+to help you get your feet wet with database access in enterprise Java.
+
+System requirements
+-------------------
+
+All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven
+3.0 or better.
+
+The application this project produces is designed to be run on a JBoss AS 7 or EAP 6.
+The following instructions target JBoss AS 7, but they also apply to JBoss EAP 6.
+
+With the prerequisites out of the way, you're ready to build and deploy.
+
+
+Adding correct Dependencies
+---------------------------
+
+JBoss AS7 (or EAP 6) provides both JPA as well as Hibernate4(as ORM) and also supports Hibernate3 etc.
+If you choose to use Hibernate4 packaged within JBoss AS7(or EAP6) you will need to first import the JPA API.
+This quickstart demonstrates usage of Hibernate Session and Hibernate Validators.
+You will also need to add dependencies to the required Hibernate modules for using these features in pom.xml with scope as provided.
+for eg .
+
+
+ org.hibernate
+ hibernate-validator
+ 4.2.0.Final
+ provided
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+
+You may refer "Adding a new external dependency" located at http://community.jboss.org/wiki/HackingOnAS7 for further help on adding dependencies.
+
+Please note that if you are working with Hibernate 3 the process is different as you will need to bundle the jars since JBoss AS7(or EAP6)
+does not ship with Hibernate 3.
+Please refer to the quickstart demonstrating Hibernate3 for details on how to bundle the jars in such cases.
+
+
+Deploying the application
+-------------------------
+
+First you need to start JBoss AS 7 (or EAP 6). To do this, run
+
+ $JBOSS_HOME/bin/standalone.sh
+
+or if you are using windows
+
+ $JBOSS_HOME/bin/standalone.bat
+
+To deploy the application, you first need to produce the archive to deploy using
+the following Maven goal:
+
+ mvn package
+
+You can now deploy the artifact to JBoss AS by executing the following command:
+
+ mvn jboss-as:deploy
+
+This will deploy `target/jboss-as-hibernate4.war`.
+
+The application will be running at the following URL .
+
+To undeploy from JBoss AS, run this command:
+
+ mvn jboss-as:undeploy
+
+You can also start JBoss AS 7 and deploy the project using Eclipse. See the JBoss AS 7
+Getting Started Guide for Developers for more information.
+
+Importing the project into an IDE
+=================================
+
+If you created the project using the Maven archetype wizard in your IDE
+(Eclipse, NetBeans or IntelliJ IDEA), then there is nothing to do. You should
+already have an IDE project.
+
+Detailed instructions for using Eclipse with JBoss AS 7 are provided in the
+JBoss AS 7 Getting Started Guide for Developers.
+
+If you created the project from the commandline using archetype:generate, then
+you need to import the project into your IDE. If you are using NetBeans 6.8 or
+IntelliJ IDEA 9, then all you have to do is open the project as an existing
+project. Both of these IDEs recognize Maven projects natively.
+
+Downloading the sources and Javadocs
+====================================
+
+If you want to be able to debug into the source code or look at the Javadocs
+of any library in the project, you can run either of the following two
+commands to pull them into your local repository. The IDE should then detect
+them.
+
+ mvn dependency:sources
+ mvn dependency:resolve -Dclassifier=javadoc
diff --git a/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/controller/MemberRegistration.java b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/controller/MemberRegistration.java
new file mode 100644
index 0000000000..e616ce4282
--- /dev/null
+++ b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/controller/MemberRegistration.java
@@ -0,0 +1,73 @@
+package org.jboss.as.quickstart.hibernate4.controller;
+
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Stateful;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Model;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import org.hibernate.Session;
+
+import org.jboss.as.quickstart.hibernate4.model.Member;
+
+/**
+ * @author Madhumita Sadhukhan
+ */
+// The @Stateful annotation eliminates the need for manual transaction demarcation
+@Stateful
+// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an
+// EL name
+// Read more about the @Model stereotype in this FAQ:
+// http://sfwk.org/Documentation/WhatIsThePurposeOfTheModelAnnotation
+@Model
+public class MemberRegistration {
+
+ @Inject
+ private Logger log;
+
+ @Inject
+ private EntityManager em;
+
+ @Inject
+ private Event memberEventSrc;
+
+ private Member newMember;
+
+ @Produces
+ @Named
+ public Member getNewMember() {
+ return newMember;
+ }
+
+ @Produces
+ public void register() throws Exception {
+ log.info("Registering " + newMember.getName());
+
+ //using Hibernate session(Native API) and JPA entitymanager
+ Session session = (Session)em.getDelegate();
+ session.persist(newMember);
+
+ try
+ {
+ memberEventSrc.fire(newMember);
+ }
+ catch(Exception e)
+ {
+ log.info("Registration Failed!You have provided duplicate details for Member!!!");
+ e.printStackTrace();
+ }
+
+
+
+ initNewMember();
+ }
+
+ @PostConstruct
+ public void initNewMember() {
+ newMember = new Member();
+ }
+}
diff --git a/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/data/MemberListProducer.java b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/data/MemberListProducer.java
new file mode 100644
index 0000000000..ebbbfe8495
--- /dev/null
+++ b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/data/MemberListProducer.java
@@ -0,0 +1,51 @@
+package org.jboss.as.quickstart.hibernate4.data;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.criterion.Order;
+import org.jboss.as.quickstart.hibernate4.model.Member;
+import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.event.Reception;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+
+/**
+ * @author Madhumita Sadhukhan
+ */
+
+@RequestScoped
+public class MemberListProducer {
+ @Inject
+ private EntityManager em;
+
+ private List members;
+
+ // @Named provides access the return value via the EL variable name "members" in the UI (e.g.,
+ // Facelets or JSP view)
+ @Produces
+ @Named
+ public List getMembers() {
+ return members;
+ }
+
+ public void onMemberListChanged(@Observes(notifyObserver = Reception.IF_EXISTS) final Member member) {
+ retrieveAllMembersOrderedByName();
+ }
+
+ @PostConstruct
+ public void retrieveAllMembersOrderedByName() {
+
+ //using Hibernate Session and Criteria Query via Hibernate Native API
+ Session session = (Session) em.getDelegate();
+ Criteria cb = session.createCriteria(Member.class);
+ cb.addOrder(Order.asc("name"));
+ members = (List)cb.list();
+
+ }
+}
diff --git a/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/model/Member.java b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/model/Member.java
new file mode 100644
index 0000000000..f84828940e
--- /dev/null
+++ b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/model/Member.java
@@ -0,0 +1,97 @@
+package org.jboss.as.quickstart.hibernate4.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/*use hibernate4 specific validators
+ *please note for hibernate3 these imports will differ
+ *for eg import org.hibernate.validator.Email
+*/
+import org.hibernate.validator.constraints.Email;
+import org.hibernate.validator.constraints.NotEmpty;
+
+/*The Model uses JPA Entity as well as Hibernate Validators
+ *
+ */
+
+@Entity
+@XmlRootElement
+@Table(name = "MemberHibernate4Demo",uniqueConstraints = @UniqueConstraint(columnNames = "id"))
+public class Member implements Serializable {
+ /** Default value included to remove warning. Remove or modify at will. **/
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private Long id;
+
+ @NotNull
+ @Size(min = 1, max = 25)
+ @Pattern(regexp = "[A-Za-z ]*", message = "must contain only letters and spaces")
+ private String name;
+
+ /**using hibernate4 validators**/
+ @NotNull
+ @NotEmpty
+ @Email
+ private String email;
+
+ @NotNull
+ @Size(min = 9, max = 12)
+ @Digits(fraction = 0, integer = 12)
+ @Column(name = "phone_number")
+ private String phoneNumber;
+
+ private String address;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+}
diff --git a/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/util/Resources.java b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/util/Resources.java
new file mode 100644
index 0000000000..1626a2b71b
--- /dev/null
+++ b/hibernate4/src/main/java/org/jboss/as/quickstart/hibernate4/util/Resources.java
@@ -0,0 +1,33 @@
+package org.jboss.as.quickstart.hibernate4.util;
+
+import java.util.logging.Logger;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ * This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans
+ *
+ *
+ * Example injection on a managed bean field:
+ *
+ *
+ *
+ * @Inject
+ * private EntityManager em;
+ *
+ */
+public class Resources {
+ // use @SuppressWarnings to tell IDE to ignore warnings about field not being referenced directly
+ @SuppressWarnings("unused")
+ @Produces
+ @PersistenceContext
+ private EntityManager em;
+
+ @Produces
+ public Logger produceLog(InjectionPoint injectionPoint) {
+ return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
+ }
+}
diff --git a/hibernate4/src/main/resources/META-INF/persistence.xml b/hibernate4/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000000..ea3fca0971
--- /dev/null
+++ b/hibernate4/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ java:jboss/datasources/ExampleDS
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/hibernate4/src/main/resources/import.sql b/hibernate4/src/main/resources/import.sql
new file mode 100644
index 0000000000..95be160cd7
--- /dev/null
+++ b/hibernate4/src/main/resources/import.sql
@@ -0,0 +1,3 @@
+-- You can use this file to load seed data into the database using SQL statements
+insert into MemberHibernate4Demo (id, name, email, phone_number, address) values (0, 'John Smith', 'john.smith@mailinator.com', '2125551212', 'Boston NY')
+insert into MemberHibernate4Demo (id, name, email, phone_number, address) values (1, 'Madhumita Sadhukhan', 'msadhukh@gmail.com', '2135551214', 'Brno CZ')
diff --git a/hibernate4/src/main/webapp/WEB-INF/beans.xml b/hibernate4/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000000..c782f570a2
--- /dev/null
+++ b/hibernate4/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/hibernate4/src/main/webapp/WEB-INF/faces-config.xml b/hibernate4/src/main/webapp/WEB-INF/faces-config.xml
new file mode 100644
index 0000000000..705006634f
--- /dev/null
+++ b/hibernate4/src/main/webapp/WEB-INF/faces-config.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
diff --git a/hibernate4/src/main/webapp/WEB-INF/templates/default.xhtml b/hibernate4/src/main/webapp/WEB-INF/templates/default.xhtml
new file mode 100644
index 0000000000..c505541265
--- /dev/null
+++ b/hibernate4/src/main/webapp/WEB-INF/templates/default.xhtml
@@ -0,0 +1,84 @@
+
+
+
+ Java EE 6 Starter Application
+
+
+
+
+