[jboss-cvs] JBossAS SVN: r83653 - in projects/ejb3/trunk/docs/tutorial: guide/en/modules and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 30 03:21:51 EST 2009


Author: jaikiran
Date: 2009-01-30 03:21:51 -0500 (Fri, 30 Jan 2009)
New Revision: 83653

Added:
   projects/ejb3/trunk/docs/tutorial/hibernate/
   projects/ejb3/trunk/docs/tutorial/hibernate/META-INF/
   projects/ejb3/trunk/docs/tutorial/hibernate/META-INF/persistence.xml
   projects/ejb3/trunk/docs/tutorial/hibernate/build.xml
   projects/ejb3/trunk/docs/tutorial/hibernate/customer.hbm.xml
   projects/ejb3/trunk/docs/tutorial/hibernate/jndi.properties
   projects/ejb3/trunk/docs/tutorial/hibernate/log4j.xml
   projects/ejb3/trunk/docs/tutorial/hibernate/pom.xml
   projects/ejb3/trunk/docs/tutorial/hibernate/src/
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/Customer.java
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/AnotherCustomerBean.java
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerBean.java
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerRemote.java
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/client/
   projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/client/Client.java
Modified:
   projects/ejb3/trunk/docs/tutorial/guide/en/modules/hibernate.xml
Log:
EJBTHREE-1706 Tutorial and guide for accessing org.hibernate.Session from EntityManager

Modified: projects/ejb3/trunk/docs/tutorial/guide/en/modules/hibernate.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/guide/en/modules/hibernate.xml	2009-01-30 08:09:58 UTC (rev 83652)
+++ projects/ejb3/trunk/docs/tutorial/guide/en/modules/hibernate.xml	2009-01-30 08:21:51 UTC (rev 83653)
@@ -47,7 +47,8 @@
 	<sect5>
       Accessing org.hibernate.Session and org.hibernate.Query from EntityManager:
       <para>
-         You can get access to the current underlying Hibernate Session by typecasting your reference to EntityManager.
+         You can get access to the current underlying Hibernate Session by calling the <literal>getDelegate</literal> method on the 
+         EntityManager :
       
       	<programlisting>
       		<![CDATA[
@@ -60,12 +61,11 @@
    @PersistenceContext
    private EntityManager em;
          	
-	public Customer getCustomer(long id)
-	{
-      	org.jboss.ejb3.entity.HibernateSession hibernateSession = (HibernateSession) em;
-      	org.hibernate.Session session = hibernateSession.getHibernateSession();
-      	return (Customer) session.get(Customer.class, id);
-	}
+   public Customer getCustomer(long id)
+   {
+      org.hibernate.Session session = (Session) em.getDelegate();
+      return (Customer) session.get(Customer.class, id);
+   }
 ...
 			]]>
       	</programlisting>
@@ -123,7 +123,7 @@
      [java] Found customer Jai NoLastName with id = 3
      [java] Searching for customers with first name Jai
      [java] Found 2 customers with first name Jai
-     [java] Searching for customers with first name Jai
+     [java] Searching for customers with first name Jaikiran
      [java] Found 1 customers with first name Jaikiran
      
      ]]>

Added: projects/ejb3/trunk/docs/tutorial/hibernate/META-INF/persistence.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/META-INF/persistence.xml	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/META-INF/persistence.xml	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,13 @@
+<?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"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+   version="1.0">
+   <persistence-unit name="tempdb">
+      <jta-data-source>java:/DefaultDS</jta-data-source>
+      <properties>
+          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+      </properties>
+   </persistence-unit>
+</persistence>

Added: projects/ejb3/trunk/docs/tutorial/hibernate/build.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/build.xml	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/build.xml	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,105 @@
+<?xml version="1.0"?>
+
+<!-- ======================================================================= -->
+<!-- JBoss build file                                                       -->
+<!-- ======================================================================= -->
+
+<project name="JBoss" default="ejbjar" basedir=".">
+
+   <property environment="env"/>
+   <property name="src.dir" value="${basedir}/src"/>
+   <property name="jboss.home" value="${env.JBOSS_HOME}"/>
+   <property name="jboss.server.config" value="default"/>
+   <property name="build.dir" value="${basedir}/build"/>
+   <property name="build.classes.dir" value="${build.dir}/classes"/>
+   <property name="build.artifact" value="jboss-ejb3-tutorial-hibernate.jar"/>
+
+   <!-- Build classpath -->
+   <path id="classpath">
+      <!-- So that we can get jndi.properties for InitialContext -->
+      <pathelement location="${basedir}"/>
+   		<!-- Only the jbossall-client.jar should ideally be sufficient -->
+      <fileset dir="${jboss.home}/client">
+         <include name="**/jbossall-client.jar"/>
+      </fileset>
+	<!-- Hibernate core -->
+		<fileset dir="${jboss.home}/common/lib">
+	   			<include name="hibernate-core.jar"/>
+	   	</fileset>
+	<!-- Hibernate entity manager -->
+	<fileset dir="${jboss.home}/common/lib">
+   			<include name="hibernate-entitymanager.jar"/>
+   	</fileset>
+	<!-- org.jboss.ejb3.entity.* -->
+	<fileset dir="${jboss.home}/common/lib">
+   			<include name="jboss-ejb3-core.jar"/>
+   	</fileset>
+
+	<!-- javax.persistence.* -->
+		<fileset dir="${jboss.home}/common/lib">
+	   			<include name="ejb3-persistence.jar"/>
+	   	</fileset>
+
+      <pathelement location="${build.classes.dir}"/>
+   </path>
+
+   <property name="build.classpath" refid="classpath"/>
+
+   <!-- =================================================================== -->
+   <!-- Prepares the build directory                                        -->
+   <!-- =================================================================== -->
+   <target name="prepare">
+      <mkdir dir="${build.dir}"/>
+      <mkdir dir="${build.classes.dir}"/>
+   </target>
+
+   <!-- =================================================================== -->
+   <!-- Compiles the source code                                            -->
+   <!-- =================================================================== -->
+   <target name="compile" depends="prepare">
+      <javac srcdir="${src.dir}"
+         destdir="${build.classes.dir}"
+         debug="on"
+         deprecation="on"
+         optimize="off"
+         includes="**">
+         <classpath refid="classpath"/>
+      </javac>
+   </target>
+
+   <target name="ejbjar" depends="compile">
+      <jar jarfile="build/${build.artifact}">
+         <fileset dir="${build.classes.dir}">
+            <include name="**/*.class"/>
+         </fileset>
+         <fileset dir=".">
+            <include name="META-INF/persistence.xml"/>
+         </fileset>
+      	<fileset dir="${basedir}">
+      	     <include name="*.hbm.xml"/>
+      	</fileset>
+      </jar>
+      <copy file="build/${build.artifact}" todir="${jboss.home}/server/${jboss.server.config}/deploy"/>
+   </target>
+
+   <target name="run" depends="ejbjar">
+      <java classname="org.jboss.tutorial.hibernate.client.Client" fork="yes" dir=".">
+         <classpath refid="classpath"/>
+      </java>
+   </target>
+
+   <!-- =================================================================== -->
+   <!-- Cleans up generated stuff                                           -->
+   <!-- =================================================================== -->
+   <target name="clean.db">
+      <delete dir="${jboss.home}/server/${jboss.server.config}/data/hypersonic"/>
+   </target>
+
+   <target name="clean">
+      <delete dir="${build.dir}"/>
+      <delete file="${jboss.home}/server/${jboss.server.config}/deploy/${build.artifact}"/>
+   </target>
+
+
+</project>
+

Added: projects/ejb3/trunk/docs/tutorial/hibernate/customer.hbm.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/customer.hbm.xml	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/customer.hbm.xml	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+           "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+           "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+   <class name="org.jboss.tutorial.hibernate.Customer"
+      table="Customer"
+      lazy="false">
+      <id name="id"
+         type="long"
+         access="property">
+         <generator class="native"/>
+      </id>
+      <property name="fname"
+         access="property"/>
+      <property name="lname"
+         access="property"/>
+   </class>
+</hibernate-mapping>

Added: projects/ejb3/trunk/docs/tutorial/hibernate/jndi.properties
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/jndi.properties	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/jndi.properties	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+java.naming.provider.url=localhost

Added: projects/ejb3/trunk/docs/tutorial/hibernate/log4j.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/log4j.xml	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/log4j.xml	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 32809 2005-06-24 04:49:29Z bill $ -->
+
+<!--
+   | For more configuration infromation and examples see the Jakarta Log4j
+   | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+   
+<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
+      <param name="Target" value="System.out"/>
+      <param name="Threshold" value="INFO"/>
+
+      <layout class="org.apache.log4j.PatternLayout">
+         <!-- The default pattern: Date Priority [Category] Messagen -->
+         <!--
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+         -->
+         <param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L)  -%m%n"/>
+      </layout>
+</appender>
+
+   <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>

Added: projects/ejb3/trunk/docs/tutorial/hibernate/pom.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/pom.xml	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/pom.xml	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  
+
+  
+   
+  <!-- Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.jboss.ejb3</groupId>
+    <artifactId>jboss-ejb3-tutorial-common</artifactId>
+    <version>0.1.0-SNAPSHOT</version>
+    <relativePath>../common/</relativePath>
+  </parent>
+
+  <properties>
+    <ejb3.tutorial.client>org.jboss.tutorial.hibernate.client.Client</ejb3.tutorial.client>
+  </properties>
+
+
+  <artifactId>jboss-ejb3-tutorial-hibernate</artifactId>
+  <version>0.1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>Injecting Hibernate Session and Session Factory in JBoss EJB3</name>
+  <url>http://labs.jboss.com/jbossejb3/</url>
+  <description>
+	Injecting Hibernate Session and Session Factory in JBoss EJB3
+  </description>
+  
+  <build>
+  	<!-- If the child pom has a "resources" configuration, then the "resources" from parent are NOT
+  		 inherited. So let's repeat all the resources specified in parent and then include the ones
+  		 specific to this tutorial -->
+  	
+  		<!--  Include the jndi.properties and the log4j.xml in the classpath -->
+   		<resources>
+   			<!-- Include files from the root of the tutorial into the
+   			root of output artifact jar -->
+   			<resource>
+   				<directory>./</directory>
+   				<includes>
+   					<include>*.properties</include>
+   					<include>log4j.xml</include>
+   				</includes>
+   			</resource>
+   			<!--  Include xml files from the META-INF of the tutorial into the
+   			META-INF folder of output artifact jar
+   			 -->
+   			<resource>
+   				
+   				<directory>./META-INF</directory>
+   				<includes>
+   					<include>*.xml</include>
+   				</includes>
+   				<targetPath>META-INF</targetPath>
+   			</resource>
+   			
+   			<!--  The .hbm.xml files -->
+   			<resource>
+   				<directory>./</directory>
+   				<includes>
+   					<include>*.hbm.xml</include>
+   				</includes>
+   			</resource>
+   			
+   			
+   		</resources>
+  
+  </build>
+  
+  
+</project>


Property changes on: projects/ejb3/trunk/docs/tutorial/hibernate/pom.xml
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/Customer.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/Customer.java	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/Customer.java	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tutorial.hibernate;
+
+import java.io.Serializable;
+
+/**
+ * Customer
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class Customer implements Serializable
+{
+
+   private long id;
+
+   private String fname;
+
+   private String lname;
+
+   public String getLname()
+   {
+      return lname;
+   }
+
+   public void setLname(String lname)
+   {
+      this.lname = lname;
+   }
+
+   public long getId()
+   {
+      return id;
+   }
+
+   public void setId(long id)
+   {
+      this.id = id;
+   }
+
+   public String getFname()
+   {
+      return fname;
+   }
+
+   public void setFname(String name)
+   {
+      this.fname = name;
+   }
+
+}

Added: projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/AnotherCustomerBean.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/AnotherCustomerBean.java	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/AnotherCustomerBean.java	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tutorial.hibernate.bean;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.hibernate.Session;
+import org.hibernate.ejb.QueryImpl;
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.logging.Logger;
+import org.jboss.tutorial.hibernate.Customer;
+
+/**
+ * AnotherCustomerBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(CustomerRemote.class)
+ at RemoteBinding(jndiBinding = "AnotherCustBean")
+public class AnotherCustomerBean implements CustomerRemote
+{
+   private static Logger logger = Logger.getLogger(AnotherCustomerBean.class);
+
+   @PersistenceContext
+   private EntityManager em;
+
+   public long createCustomer(String fname, String lname)
+   {
+      Customer customer = new Customer();
+      customer.setFname(fname);
+      customer.setLname(lname);
+      this.em.persist(customer);
+      logger.info("Created new customer with name = " + fname + " " + lname + " with id = " + customer.getId());
+      return customer.getId();
+
+   }
+
+   public Customer getCustomer(long id)
+   {
+      org.hibernate.Session session = (Session) em.getDelegate();
+      return (Customer) session.get(Customer.class, id);
+   }
+
+   public List<Customer> getCustomers(String fname)
+   {
+      org.hibernate.ejb.QueryImpl queryImpl = (QueryImpl) em.createQuery("from Customer where fname ='" + fname + "'");
+      org.hibernate.Query query = queryImpl.getHibernateQuery();
+      return query.list();
+   }
+
+}

Added: projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerBean.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerBean.java	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerBean.java	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tutorial.hibernate.bean;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.persistence.PersistenceContext;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.logging.Logger;
+import org.jboss.tutorial.hibernate.Customer;
+
+/**
+ * CustomerBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(CustomerRemote.class)
+ at RemoteBinding(jndiBinding = "CustBean")
+public class CustomerBean implements CustomerRemote
+{
+
+   private static Logger logger = Logger.getLogger(CustomerBean.class);
+
+   @PersistenceContext
+   private Session session;
+
+   public long createCustomer(String fname, String lname)
+   {
+      Customer customer = new Customer();
+      customer.setFname(fname);
+      customer.setLname(lname);
+      this.session.persist(customer);
+      logger.info("Created new customer with name = " + fname + " " + lname + " with id = " + customer.getId());
+      return customer.getId();
+   }
+
+   public Customer getCustomer(long id)
+   {
+      return (Customer) this.session.get(Customer.class, id);
+   }
+
+   public List<Customer> getCustomers(String fname)
+   {
+      Query hql = this.session.createQuery("from Customer where fname = '" + fname + "'");
+      return hql.list();
+   }
+
+}

Added: projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerRemote.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerRemote.java	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/bean/CustomerRemote.java	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tutorial.hibernate.bean;
+
+import java.util.List;
+
+import org.jboss.tutorial.hibernate.Customer;
+
+/**
+ * CustomerRemote
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface CustomerRemote
+{
+
+   long createCustomer(String fname, String lname);
+   
+   Customer getCustomer(long id);
+   
+   List<Customer> getCustomers(String fname); 
+}

Added: projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/client/Client.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/client/Client.java	                        (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/hibernate/src/org/jboss/tutorial/hibernate/client/Client.java	2009-01-30 08:21:51 UTC (rev 83653)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tutorial.hibernate.client;
+
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.tutorial.hibernate.bean.CustomerRemote;
+
+import org.jboss.tutorial.hibernate.Customer;
+
+/**
+ * Client
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class Client
+{
+
+   public static void main(String args[]) throws Exception
+   {
+      Context ctx = new InitialContext();
+      CustomerRemote customerBean = (CustomerRemote) ctx.lookup("CustBean");
+      // let's create customer#1
+      long id = customerBean.createCustomer("Jai", "Pai");
+      System.out.println("Jai Pai created with id = " + id);
+
+      //let's create customer#2
+      long custId2 = customerBean.createCustomer("Jaikiran", "Pai");
+      System.out.println("Jaikiran Pai created with id = " + custId2);
+
+      //one more customer
+      long custId3 = customerBean.createCustomer("Jai", "NoLastName");
+      System.out.println("Jai NoLastName created with id = " + custId3);
+
+      // now let's find customer with some specific id
+      System.out.println("Searching for customer with id = " + custId2);
+      Customer customer = customerBean.getCustomer(custId2);
+      System.out.println("Found customer " + customer.getFname() + " " + customer.getLname() + " with id = " + custId2);
+
+      
+      //let's use the other bean to search another customer
+      CustomerRemote anotherCustomerBean = (CustomerRemote) ctx.lookup("AnotherCustBean");
+      System.out.println("Searching for customer with id = " + custId3);
+      Customer oneMoreCustomer = anotherCustomerBean.getCustomer(custId3);
+      System.out.println("Found customer " + oneMoreCustomer.getFname() + " " + oneMoreCustomer.getLname() + " with id = " + custId3);
+
+      // now let's find customers with first name=Jai
+      System.out.println("Searching for customers with first name Jai");
+      List<Customer> customers = customerBean.getCustomers("Jai");
+      System.out.println("Found " + customers.size() + " customers with first name Jai");
+      
+      // let's use the other bean to find customers with name Jaikiran
+      System.out.println("Searching for customers with first name Jaikiran");
+      List<Customer> moreCustomers = anotherCustomerBean.getCustomers("Jaikiran");
+      System.out.println("Found " + moreCustomers.size() + " customers with first name Jaikiran");
+      
+
+   }
+}




More information about the jboss-cvs-commits mailing list