Author: steve.ebersole(a)jboss.com
Date: 2007-05-26 00:50:07 -0400 (Sat, 26 May 2007)
New Revision: 11570
Added:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Event.java
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Person.java
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/util/
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/util/HibernateUtil.java
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManager.java
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManagerServlet.java
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionFactoryInitializer.java
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionInterceptor.java
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Event.hbm.xml
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Person.hbm.xml
Removed:
trunk/Hibernate3/documentation/tutorial/src/main/java/events/
trunk/Hibernate3/documentation/tutorial/src/main/java/util/
Modified:
trunk/Hibernate3/documentation/tutorial/pom.xml
trunk/Hibernate3/documentation/tutorial/src/main/resources/hibernate.cfg.xml
trunk/Hibernate3/documentation/tutorial/src/main/resources/log4j.properties
trunk/Hibernate3/documentation/tutorial/src/main/webapp/WEB-INF/web.xml
Log:
completed migration of tutorial
Modified: trunk/Hibernate3/documentation/tutorial/pom.xml
===================================================================
--- trunk/Hibernate3/documentation/tutorial/pom.xml 2007-05-26 03:48:22 UTC (rev 11569)
+++ trunk/Hibernate3/documentation/tutorial/pom.xml 2007-05-26 04:50:07 UTC (rev 11570)
@@ -1,27 +1,32 @@
-<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/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core-project</artifactId>
- <version>3.3.0.beta1</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-tutorial</artifactId>
- <packaging>jar</packaging>
- <name>Hibernate Tutorial</name>
- <description>A tutorial project showcasing Hibernate usage</description>
-
- <dependencies>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- </dependency>
- </dependencies>
-
+<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/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core-project</artifactId>
+ <version>3.3.0.beta1</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-tutorial</artifactId>
+ <packaging>war</packaging>
+ <name>Hibernate Tutorial</name>
+ <description>A tutorial project showcasing Hibernate usage</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.3</version>
+ </dependency>
+ </dependencies>
+
</project>
Copied:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Event.java
(from rev 11563, trunk/Hibernate3/documentation/tutorial/src/main/java/events/Event.java)
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Event.java
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Event.java 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,48 @@
+package org.hibernate.tutorial.domain;
+
+import java.util.*;
+
+public class Event {
+ private Long id;
+
+ private String title;
+ private Date date;
+
+ public Event() {}
+
+ public Long getId() {
+ return id;
+ }
+
+ private void setId(Long id) {
+ this.id = id;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+
+ private Set participants = new HashSet();
+
+ public Set getParticipants() {
+ return participants;
+ }
+
+ public void setParticipants(Set participants) {
+ this.participants = participants;
+ }
+
+}
\ No newline at end of file
Copied:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Person.java
(from rev 11563,
trunk/Hibernate3/documentation/tutorial/src/main/java/events/Person.java)
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Person.java
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/domain/Person.java 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,80 @@
+package org.hibernate.tutorial.domain;
+
+import java.util.*;
+
+public class Person {
+
+ private Long id;
+ private int age;
+ private String firstname;
+ private String lastname;
+
+ public Person() {}
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+
+ public String getLastname() {
+ return lastname;
+ }
+
+ public void setLastname(String lastname) {
+ this.lastname = lastname;
+ }
+
+
+ private Set emailAddresses = new HashSet();
+
+ public Set getEmailAddresses() {
+ return emailAddresses;
+ }
+
+ public void setEmailAddresses(Set emailAddresses) {
+ this.emailAddresses = emailAddresses;
+ }
+
+
+ private Set events = new HashSet();
+
+ // Defensive, convenience methods
+ protected Set getEvents() {
+ return events;
+ }
+
+ protected void setEvents(Set events) {
+ this.events = events;
+ }
+
+ public void addToEvent(Event event) {
+ this.getEvents().add(event);
+ event.getParticipants().add(this);
+ }
+
+ public void removeFromEvent(Event event) {
+ this.getEvents().remove(event);
+ event.getParticipants().remove(this);
+ }
+
+}
\ No newline at end of file
Copied:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/util/HibernateUtil.java
(from rev 11563,
trunk/Hibernate3/documentation/tutorial/src/main/java/util/HibernateUtil.java)
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/util/HibernateUtil.java
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/util/HibernateUtil.java 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,25 @@
+package org.hibernate.tutorial.util;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+public class HibernateUtil {
+
+ private static final SessionFactory sessionFactory;
+
+ static {
+ try {
+ // Create the SessionFactory from hibernate.cfg.xml
+ sessionFactory = new Configuration().configure().buildSessionFactory();
+ } catch (Throwable ex) {
+ // Make sure you log the exception, as it might be swallowed
+ System.err.println("Initial SessionFactory creation failed." +
ex);
+ throw new ExceptionInInitializerError(ex);
+ }
+ }
+
+ public static SessionFactory getSessionFactory() {
+ return sessionFactory;
+ }
+
+}
\ No newline at end of file
Copied:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManager.java
(from rev 11563,
trunk/Hibernate3/documentation/tutorial/src/main/java/events/EventManager.java)
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManager.java
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManager.java 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,138 @@
+package org.hibernate.tutorial.web;
+
+import java.util.Date;
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.tutorial.domain.Event;
+import org.hibernate.tutorial.domain.Person;
+import org.hibernate.tutorial.util.HibernateUtil;
+
+public class EventManager {
+
+ public static void main(String[] args) {
+ EventManager mgr = new EventManager();
+
+ if (args[0].equals("store")) {
+ mgr.createAndStoreEvent("My Event", new Date());
+ }
+ else if (args[0].equals("list")) {
+ List events = mgr.listEvents();
+ for (int i = 0; i < events.size(); i++) {
+ Event theEvent = (Event) events.get(i);
+ System.out.println("Event: " + theEvent.getTitle() +
+ " Time: " + theEvent.getDate());
+ }
+ }
+ else if (args[0].equals("addpersontoevent")) {
+ Long eventId = mgr.createAndStoreEvent("My Event", new Date());
+ Long personId = mgr.createAndStorePerson("Foo", "Bar");
+ mgr.addPersonToEvent(personId, eventId);
+ System.out.println("Added person " + personId + " to event
" + eventId);
+ }
+ else if (args[0].equals("addemailtoperson")) {
+ Long personId = mgr.createAndStorePerson("Foozy",
"Beary");
+ mgr.addEmailToPerson(personId, "foo@bar");
+ mgr.addEmailToPerson(personId, "bar@foo");
+ System.out.println("Added two email addresses (value typed objects) to
person entity : " + personId);
+ }
+
+ HibernateUtil.getSessionFactory().close();
+ }
+
+ private Long createAndStoreEvent(String title, Date theDate) {
+
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+ session.beginTransaction();
+
+ Event theEvent = new Event();
+ theEvent.setTitle(title);
+ theEvent.setDate(theDate);
+
+ session.save(theEvent);
+
+ session.getTransaction().commit();
+
+ return theEvent.getId();
+ }
+
+ private Long createAndStorePerson(String firstname, String lastname) {
+
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+ session.beginTransaction();
+
+ Person thePerson = new Person();
+ thePerson.setFirstname(firstname);
+ thePerson.setLastname(lastname);
+
+ session.save(thePerson);
+
+ session.getTransaction().commit();
+
+ return thePerson.getId();
+ }
+
+
+ private List listEvents() {
+
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+ session.beginTransaction();
+
+ List result = session.createQuery("from Event").list();
+
+ session.getTransaction().commit();
+
+ return result;
+ }
+
+ private void addPersonToEvent(Long personId, Long eventId) {
+
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+ session.beginTransaction();
+
+ Person aPerson = (Person) session
+ .createQuery("select p from Person p left join fetch p.events where
p.id = :pid")
+ .setParameter("pid", personId)
+ .uniqueResult(); // Eager fetch the collection so we can use it detached
+
+ Event anEvent = (Event) session.load(Event.class, eventId);
+ // If we want to handle it bidirectional and detached, we also need to load this
+ // collection with an eager outer-join fetch, this time with Criteria and not
HQL:
+ /*
+ Event anEvent = (Event) session
+ .createCriteria(Event.class).setFetchMode("participants",
FetchMode.JOIN)
+ .add( Expression.eq("id", eventId) )
+ .uniqueResult(); // Eager fetch the colleciton so we can use it detached
+ */
+
+ session.getTransaction().commit();
+
+ // End of first unit of work
+
+ aPerson.addToEvent( anEvent );
+ // or bidirectional safety method, setting both sides:
aPerson.addToEvent(anEvent);
+
+ // Begin second unit of work
+
+ Session session2 = HibernateUtil.getSessionFactory().getCurrentSession();
+ session2.beginTransaction();
+
+ session2.update(aPerson); // Reattachment of aPerson
+
+ session2.getTransaction().commit();
+ }
+
+ private void addEmailToPerson(Long personId, String emailAddress) {
+
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+ session.beginTransaction();
+
+ Person aPerson = ( Person ) session.load(Person.class, personId);
+
+ // The getEmailAddresses() might trigger a lazy load of the collection
+ aPerson.getEmailAddresses().add(emailAddress);
+
+ session.getTransaction().commit();
+ }
+
+}
\ No newline at end of file
Copied:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManagerServlet.java
(from rev 11563,
trunk/Hibernate3/documentation/tutorial/src/main/java/events/EventManagerServlet.java)
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManagerServlet.java
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/EventManagerServlet.java 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,106 @@
+package org.hibernate.tutorial.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.hibernate.tutorial.domain.Event;
+import org.hibernate.tutorial.util.HibernateUtil;
+
+public class EventManagerServlet extends HttpServlet {
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy");
+
+ try {
+ // Begin unit of work
+ HibernateUtil.getSessionFactory()
+ .getCurrentSession().beginTransaction();
+
+ // Write HTML header
+ PrintWriter out = response.getWriter();
+ out.println("<html><head><title>Event
Manager</title></head><body>");
+
+ // Handle actions
+ if ( "store".equals(request.getParameter("action")) ) {
+
+ String eventTitle = request.getParameter("eventTitle");
+ String eventDate = request.getParameter("eventDate");
+
+ if ( "".equals(eventTitle) || "".equals(eventDate) )
{
+ out.println("<b><i>Please enter event title and
date.</i></b>");
+ } else {
+ createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
+ out.println("<b><i>Added
event.</i></b>");
+ }
+ }
+
+ // Print page
+ printEventForm(out);
+ listEvents(out, dateFormatter);
+
+ // Write HTML footer
+ out.println("</body></html>");
+ out.flush();
+ out.close();
+
+ // End unit of work
+ HibernateUtil.getSessionFactory()
+ .getCurrentSession().getTransaction().commit();
+
+ } catch (Exception ex) {
+ HibernateUtil.getSessionFactory()
+ .getCurrentSession().getTransaction().rollback();
+ throw new ServletException(ex);
+ }
+ }
+
+ private void printEventForm(PrintWriter out) {
+ out.println("<h2>Add new event:</h2>");
+ out.println("<form>");
+ out.println("Title: <input name='eventTitle'
length='50'/><br/>");
+ out.println("Date (e.g. 24.12.2009): <input name='eventDate'
length='10'/><br/>");
+ out.println("<input type='submit' name='action'
value='store'/>");
+ out.println("</form>");
+ }
+
+ private void listEvents(PrintWriter out, SimpleDateFormat dateFormatter) {
+ List result = HibernateUtil.getSessionFactory()
+ .getCurrentSession().createCriteria(Event.class).list();
+ if (result.size() > 0) {
+ out.println("<h2>Events in database:</h2>");
+ out.println("<table border='1'>");
+ out.println("<tr>");
+ out.println("<th>Event title</th>");
+ out.println("<th>Event date</th>");
+ out.println("</tr>");
+ for (Iterator it = result.iterator(); it.hasNext();) {
+ Event event = (Event) it.next();
+ out.println("<tr>");
+ out.println("<td>" + event.getTitle() +
"</td>");
+ out.println("<td>" +
dateFormatter.format(event.getDate()) + "</td>");
+ out.println("</tr>");
+ }
+ out.println("</table>");
+ }
+ }
+
+ protected void createAndStoreEvent(String title, Date theDate) {
+ Event theEvent = new Event();
+ theEvent.setTitle(title);
+ theEvent.setDate(theDate);
+
+ HibernateUtil.getSessionFactory()
+ .getCurrentSession().save(theEvent);
+ }
+
+}
Added:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionFactoryInitializer.java
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionFactoryInitializer.java
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionFactoryInitializer.java 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,24 @@
+package org.hibernate.tutorial.web;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.hibernate.tutorial.util.HibernateUtil;
+
+/**
+ * Demonstrates good practice of making sure the SessionFactory is initialized
+ * on application startup, rather than on first request. Here we register
+ * as a listener to the servlet context lifecycle for building/closing of the
+ * SessionFactory.
+ *
+ * @author Steve Ebersole
+ */
+public class SessionFactoryInitializer implements ServletContextListener {
+ public void contextInitialized(ServletContextEvent event) {
+ HibernateUtil.getSessionFactory();
+ }
+
+ public void contextDestroyed(ServletContextEvent event) {
+ HibernateUtil.getSessionFactory().close();
+ }
+}
Added:
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionInterceptor.java
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionInterceptor.java
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/java/org/hibernate/tutorial/web/SessionInterceptor.java 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,62 @@
+package org.hibernate.tutorial.web;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.hibernate.classic.Session;
+import org.hibernate.context.ManagedSessionContext;
+import org.hibernate.tutorial.util.HibernateUtil;
+
+/**
+ * Illustrates a servlet filter used to apply a Hibernate session
+ * to the "context" of the web request.
+ *
+ * @author Steve Ebersole
+ */
+public class SessionInterceptor implements Filter {
+
+ private static final Log log = LogFactory.getLog( SessionInterceptor.class );
+
+ public void doFilter(
+ ServletRequest request,
+ ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ log.trace( "===> opening session for request [" + request.hashCode() +
"]" );
+ // Start the session to be used for this request
+ Session session = HibernateUtil.getSessionFactory().openSession();
+
+ try {
+ // make the session available to the session factory's "current
context"
+ ManagedSessionContext.bind( session );
+
+ // pass control along to the rest of the processing chain
+ chain.doFilter( request, response );
+ }
+ finally {
+ log.trace( "===> cleaning-up session for request [" + request.hashCode()
+ "]" );
+ // remove session from "current context"
+ ManagedSessionContext.unbind( HibernateUtil.getSessionFactory() );
+
+ try {
+ session.close();
+ }
+ catch( Throwable t ) {
+ log.warn( "was unable to properly close session for request [" +
request.hashCode() + "]" );
+ }
+ }
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void destroy() {
+ }
+}
Modified: trunk/Hibernate3/documentation/tutorial/src/main/resources/hibernate.cfg.xml
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/resources/hibernate.cfg.xml 2007-05-26
03:48:22 UTC (rev 11569)
+++
trunk/Hibernate3/documentation/tutorial/src/main/resources/hibernate.cfg.xml 2007-05-26
04:50:07 UTC (rev 11570)
@@ -14,13 +14,13 @@
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
- <property name="connection.pool_size">1</property>
+ <property name="connection.pool_size">2</property>
<!-- SQL dialect -->
<property
name="dialect">org.hibernate.dialect.HSQLDialect</property>
- <!-- Enable Hibernate's automatic session context management -->
- <property
name="current_session_context_class">thread</property>
+ <!-- Enable Hibernate's current session context -->
+ <property
name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property>
<!-- Disable the second-level cache -->
<property
name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
@@ -31,8 +31,8 @@
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
- <mapping resource="events/Event.hbm.xml"/>
- <mapping resource="events/Person.hbm.xml"/>
+ <mapping
resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
+ <mapping
resource="org/hibernate/tutorial/domain/Person.hbm.xml"/>
</session-factory>
Modified: trunk/Hibernate3/documentation/tutorial/src/main/resources/log4j.properties
===================================================================
--- trunk/Hibernate3/documentation/tutorial/src/main/resources/log4j.properties 2007-05-26
03:48:22 UTC (rev 11569)
+++ trunk/Hibernate3/documentation/tutorial/src/main/resources/log4j.properties 2007-05-26
04:50:07 UTC (rev 11570)
@@ -4,12 +4,6 @@
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
-### direct messages to file hibernate.log ###
-#log4j.appender.file=org.apache.log4j.FileAppender
-#log4j.appender.file.File=hibernate.log
-#log4j.appender.file.layout=org.apache.log4j.PatternLayout
-#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
-
### set log levels - for more verbose logging change 'info' to 'debug'
###
log4j.rootLogger=warn, stdout
Copied:
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Event.hbm.xml
(from rev 11563,
trunk/Hibernate3/documentation/tutorial/src/main/java/events/Event.hbm.xml)
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Event.hbm.xml
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Event.hbm.xml 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,23 @@
+<?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 package="org.hibernate.tutorial.domain">
+
+ <class name="Event" table="EVENTS">
+ <id name="id" column="EVENT_ID">
+ <generator class="native"/>
+ </id>
+ <property name="date" type="timestamp"
column="EVENT_DATE"/>
+ <property name="title"/>
+
+ <set name="participants" table="PERSON_EVENT"
inverse="true">
+ <key column="EVENT_ID"/>
+ <many-to-many column="PERSON_ID" class="Person"/>
+ </set>
+
+ </class>
+
+
+</hibernate-mapping>
\ No newline at end of file
Copied:
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Person.hbm.xml
(from rev 11563,
trunk/Hibernate3/documentation/tutorial/src/main/java/events/Person.hbm.xml)
===================================================================
---
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Person.hbm.xml
(rev 0)
+++
trunk/Hibernate3/documentation/tutorial/src/main/resources/org/hibernate/tutorial/domain/Person.hbm.xml 2007-05-26
04:50:07 UTC (rev 11570)
@@ -0,0 +1,28 @@
+<?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 package="org.hibernate.tutorial.domain">
+
+ <class name="Person" table="PERSON">
+ <id name="id" column="PERSON_ID">
+ <generator class="native"/>
+ </id>
+ <property name="age"/>
+ <property name="firstname"/>
+ <property name="lastname"/>
+
+ <set name="events" table="PERSON_EVENT">
+ <key column="PERSON_ID"/>
+ <many-to-many column="EVENT_ID" class="Event"/>
+ </set>
+
+ <set name="emailAddresses" table="PERSON_EMAIL_ADDR">
+ <key column="PERSON_ID"/>
+ <element type="string" column="EMAIL_ADDR"/>
+ </set>
+
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Modified: trunk/Hibernate3/documentation/tutorial/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/Hibernate3/documentation/tutorial/src/main/webapp/WEB-INF/web.xml 2007-05-26
03:48:22 UTC (rev 11569)
+++ trunk/Hibernate3/documentation/tutorial/src/main/webapp/WEB-INF/web.xml 2007-05-26
04:50:07 UTC (rev 11570)
@@ -4,13 +4,28 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <listener>
+
<listener-class>org.hibernate.tutorial.web.SessionFactoryInitializer</listener-class>
+ </listener>
+
<servlet>
<servlet-name>Event Manager</servlet-name>
- <servlet-class>events.EventManagerServlet</servlet-class>
+
<servlet-class>org.hibernate.tutorial.web.EventManagerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Event Manager</servlet-name>
<url-pattern>/eventmanager</url-pattern>
</servlet-mapping>
+
+ <filter>
+ <filter-name>Session Interceptor</filter-name>
+
<filter-class>org.hibernate.tutorial.web.SessionInterceptor</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>Session Interceptor</filter-name>
+ <servlet-name>Event Manager</servlet-name>
+ </filter-mapping>
+
</web-app>