-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: newbie notes: tutorial - first hibernate application
PostPosted: Tue Aug 22, 2006 7:50 pm 
Newbie

Joined: Thu Aug 17, 2006 7:42 pm
Posts: 2
Location: San Francisco
Newbie Developer Notes - The first Hibernate Application


start at http://www.hibernate.org/152.html





1. download, extract install file

2. place mySQL jdbc driver in hibernate/lib (mysql-connector-java-3.1.13-bin.jar)

3. copy hibernate3.jar from hibernate to hibernate/lib

4. copy junit-3.8.1.jar from hibernate/lib to ant/lib



Test install:

try to build test app per install instructions


Modify etc/hibernate.properties


hibernate.properties (MySQL properties for testing install):

hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost:3306/test
hibernate.connection.username gavin
hibernate.connection.password

-----------------------------------------------------------


Tutorial:
Chapter 1. Introduction to Hibernate
1.2. Part 1 - The first Hibernate Application



Copy and create files from tutorial as instructed:

1.Event.java, Event.hbm.xml, hibernate.cfg.xml, build.xml

*To create Event class and generate the Bean get/set methods, use Eclipse!
edit setId to be a private method .


3. make new folder hibernate/data


4. copy log4j.properties from the Hibernate distribution (it's in the etc/ directory) to your src directory, next to hibernate.cfg.xml


add callable action to build.xml:

<target name="run" depends="compile">
<java fork="true" classname="events.EventManager" classpathref="libraries">
<classpath path="${targetdir}"/>
<arg value="${action}"/>
</java>
</target>


build! check for compiled files in bin directory.


a) download hsqldb and copy hsqldb.jar into hibernate/lib
b) to start hsqldb database in hibernate/data directory, console: java -classpath ../lib/hsqldb.jar org.hsqldb.Server

c) to start hsqldb database manager in hibernate/data directory, console: java -classpath ../lib/hsqldb.jar org.hsqldb.util.DatabaseManagerSwing

*to run hsqldb: (must go up out of directory because starts from data directory ../lib/)

change hibernate.cfg.xml settings for database to:

<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>



*******************************

test:

ant run -Daction=store

after creating database in first store action, to disable re-creation by the hbm2ddl program, comment out property in hibernate.cfg.xml
<property name="hbm2ddl.auto">create</property>

run "store" several more times, loading different events from EventManager class.

Modify EventManager for list action:

When adding listEvents() to EventManager, add the imports:
// added following imports
import java.util.*;

test:
ant run -Daction=list

*******************************


enable database creation by the hbm2ddl program


To create Person class and generate the Bean get/set methods, use Eclipse!
edit setId to be a private method .



add to Person Class for events HashSet:
import java.util.*;


Some coding in EventManager...
private Long createAndStorePerson(String firstname, String lastname)


code new EventManager arguments:
storeevent, storeperson, listevents

*addPersonToEvent should be called addEventToPerson!!!!


disable database creation by the hbm2ddl program
test: storeevent
test: listevents
test: storeperson
test: addpersontoevent


create/store event and person and add person to event:
ant run -Daction=addpersontoevent



Code email address, then rebuild database - run storeevent with enable database creation by the hbm2ddl program
then disable and test all above.

code participants, then rebuild database
run storeevent
then reset rebuild to off
test all above.

*******************************


web application:

servlet compile requires j2ee javax jar: sun/appserver/lib/javaee.jar copied into hibernate/lib

Servlet requires imports:

import util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.text.*;




add to build.xml (note name of exclude file as javaee.jar, not jsdk.jar)

<target name="war" depends="compile">
<war destfile="hibernate-tutorial.war" webxml="web.xml">
<lib dir="${librarydir}">
<!-- installed javaee.jar instead of j2sdk.jar -->
<exclude name="javaee.jar"/>
</lib>
<classes dir="${targetdir}"/>
</war>
</target>




put web.xml in hibernate/ root

then ant war!
hibernate-tutorial.war goes in Tomcat5.5\webapps

start tomcat, make sure no other appservers are on or listening at port 8080!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.