Sunteți pe pagina 1din 50

HIBERNATE/Java & ORACLE

Overview of technology for


Hibernate 3
as of 1/2006
By Joel A. Thompson (joel@rhinosystemsinc.com)
Goal: Present Hibernate to first time users, and get you
started with all the major concepts right away.

copyright 2006, rhinosystemsinc.c


om all rights reserved
What we'll Cover

• Introduction of HibernateV3
Configuration & Setup of Hibernate/Java
• Code
• Pros and Cons
• RESOURCES
• Q & A.

copyright 2006, rhinosystemsinc.c


om all rights reserved
Intro:About Hibernate
• www.hibernate.org - Open Source since, and
now with JBoss (since late 2003)
w/ commercial support & training.
Founder: Gavin King
• Provides a layer for java to interact with the
database.
– Is technically a set of java-class libraries that you use to
gain access to your database
• Hibernate caches database objects
– & Hibernate services your Java program
1/3
copyright 2006, rhinosystemsinc.c
om all rights reserved
Intro:About Hibernate

• Hibernate layer resides in your JVM.


• Improves performance
– objects are cached in JVM and mapped to your
object model.
• Used in commercial applications
– JBoss for one (yes, another open source…)
– Many more opensource and commercial listed at:
http://www.hibernate.org/27.html
2/3
copyright 2006, rhinosystemsinc.c
om all rights reserved
Intro:About Hibernate

• Hibernate is highly customizable


– Caching (2nd level cache).
– Database dialects
– Transaction
– Connection pooling
– Custom Types
• Or use out of box (recommend changing: connection pooling).
3/3
copyright 2006, rhinosystemsinc.c
om all rights reserved
Intro:Importance of DAO
• DAO: Data Access Objects –
design/pattern
• Purpose is to abstract your calls to the
database.
– Don't put SQL directly into your Java/JSP.
• You can change our database with minimal
affect on your code
• Identify bottle necks and bugs easier.
1/2
copyright 2006, rhinosystemsinc.c
om all rights reserved
Intro:Importance of DAO

• Better design translates into easier to


understand code.
• Hibernate DAO - 3rd party technology
– Benefits of common knowledge
– Fixes to technology
– Specialized for each database and optimized for
database access (caveats).

2/2
copyright 2006, rhinosystemsinc.c
om all rights reserved
Intro:Comparison to SQL
• Problem with SQL
– never lived up to promise of standardization amongst
database vendors
– Uses Jdbc to access database – (no forced design)
– Is Relational
• With Hibernate:
– Caching
– Easier to code
– Standard access
– Is Object Oriented and maps to Relational.
1/2
copyright 2006, rhinosystemsinc.c
om all rights reserved
Intro:Comparison to SQL
• Speed/performance
– Prepared Statements and caching (hib)
– Can batch process many DML statements. (hib)
– Better performance from PL/SQL (sql/hib)
• Maintenance/Updates (hib)
• Legacy system (depends)
– Using hibernate with legacy database systems
& Legacy java code retrofit with Hibernate
2/2
copyright 2006, rhinosystemsinc.c
om all rights reserved
Configuration Hibernate/Java

• Download and install JDK 1.4 or 1.5


• Download version3 from
www.hibernate.org
• Setup Hibernate's Jars into your project's
classpath.
– The hibernate3.jar into your project's classpath;
and if need be all the <hib>/lib (if you don't
already have them).
1/5
copyright 2006, rhinosystemsinc.c
om all rights reserved
Config:hibernate.properties

• Make sure that Oracle's client jdbc lib is in


your CLASSPATH
• Hibernate.properties needs to be in your
project's & runtime classpath.
HIBERNATE.PROPERTIES
#for OCI (local instance of Oracle, not using tnsnames.ora).
hibernate.dialect=org.hibernate.dialect.OracleDialect
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.username=joel
hibernate.connection.password=xyz
hibernate.connection.pool_size=5
hibernate.connection.url=jdbc:oracle:oci:@
hibernate.show_sql=true

2/5
copyright 2006, rhinosystemsinc.c
om all rights reserved
Config: Download & Config
Xdoclet
[OPTIONAL]
• In order to run the "generation" of hibernate
XML you need to setup your classpath to include
Xdoclet libraries
• Download latest (v1.2.3) from
http://xdoclet.sourceforge.net/xdoclet/index.html
(www.xdoclet.org?)
– Download direct from
http://sourceforge.net/project/showfiles.php?group_id=31602
– Tag References http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-
tags.html
3/5
copyright 2006, rhinosystemsinc.c
om all rights reserved
config: Download & Config ANT

[OPTIONAL]
• In order to use ANT you'll need to setup your
PATH to include ANT. Check – run "ant"
• Download latest (v1.6.5) from http://ant.apache.org/
(www.ant.org?)
– Download direct from
http://www.axint.net/apache/ant/binaries/apache-ant-1.6.5-bin.zip
– Unzip and make sure "ant" is in your path. (right-click my computer ->
properties ->Advanced->Environmental Variables -> update PATH with directory
<ant_install>/bin)

4/5
copyright 2006, rhinosystemsinc.c
om all rights reserved
config: Download & Config ANT

• SUMMARY:
– JDK [required]: PATH,CLASSPATH
– HIBERNATE [required]: CLASSPATH
• ORACLE or DBMS client [required]:
CLASSPATH (connection/lib info w/ hibernate.properties)

– XDOCLET [optional]:CLASSPATH
– ANT [optional]:CLASSPATH

5/5
copyright 2006, rhinosystemsinc.c
om all rights reserved
Code & Fragments

• What we'll cover in the CODE section. For


each of the items below you'll see the XML,
the DDL SQL, Java code and an
explanation.
–Single Entity –Many-to-Many
–Primary Keys –DML (Query, Insert, Update, Delete)
–Many-to-One –Extra topics

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Overview
• Hibernate layer is
independent of your
code
• Entities map via
hibernate XML
• Hibernate & you:
DML, caching,
isolation levels

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Java POJO Entity
public class Person {
Long PERSON_ID=null; //manufactured surrogate key
String FIRST_NAME=null;
String LAST_NAME=null;
public Long getPERSON_ID(){…}
Standard get/set &
public void setPERSON_ID(String) {…} need empty
public String getFIRST_NAME(){…} constructor ~
public void setFIRST_NAME(String) {…}
public String getLAST_NAME(){…}
public void setLAST_NAME (String) {…}
}

See SAMPLE 0

1/4
copyright 2006, rhinosystemsinc.c
om all rights reserved
Code[0]: XML for Entity
<!--Must be named: Person.hbm.xml and reside in CLASSPATH-->
<?xml
<?xml version="1.0"
version="1.0" encoding="UTF-8"?>
encoding="UTF-8"?>
<!DOCTYPE
<!DOCTYPEhibernate-mapping
hibernate-mappingPUBLIC
PUBLIC"-//Hibernate/Hibernate Mapping
"-//Hibernate/Hibernate DTD 3.0//EN"
Mapping "http://hibernate.sourceforge.net/hibernate-mapping-
DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-
3.0.dtd">
3.0.dtd">
<hibernate-mapping>
<hibernate-mapping>
<class name="com.rhinosystemsinc.hibernate.samples_0.Person"
<id name="PERSON_ID" table="SAMPLE0_Person" >
column="PERSON_ID" type="java.lang.Long" unsaved-value="null">
<generator class="hilo">
<id name="PERSON_ID" column="PERSON_ID" type="java.lang.Long" unsaved-value="null">
<param name="table">SAMPLE0_PERSON_SEQ</param>
<generator class="hilo">
name="column">NEXT</param>
<param name="table">SAMPLE0_PERSON_SEQ</param>
</generator>
<param name="column">NEXT</param>
</id> </generator>
<property
</id>
name="FIRST_NAME"
<property
type="java.lang.String"
name="FIRST_NAME" Define the manufactured surrogate
update="true"
type="java.lang.String"
insert="true"
update="true"
primary key, based on SEQUENCE.
column="FIRST_NAME"
insert="true"
not-null="true"
column="FIRST_NAME"
unique="false"
not-null="true"
length="100"
unique="false" Also natural composite primary keys:
/>length="100"
<property
<composite-id>
/>
name="LAST_NAME"/>
<property name="LAST_NAME"/> <key-property name="name"/>
</class> <key-property name="ssn"/>
</hibernate-mapping>
</composite-id>

2/4
copyright 2006, rhinosystemsinc.c
om all rights reserved
Code: Primary Keys

• All hibernate persisted Entity mappings


must have a primary key.
• Suggestion: Use surrogate generated keys.
– Hib supports natural keys ( & multi-column).
– Reason:
• Sometimes (rarely) keys will change values
• Easier to manage

3/4
copyright 2006, rhinosystemsinc.c
om all rights reserved
Code[0]: Java Main Class
//SAVING A NEW OBJECT
org.hibernate.Session sess = sessFact.openSession(); //more on SessionFactory in a minute.
Person p = new Person();
p.setFIRST_NAME("John");
p.setLAST_NAME("Smith");
Transaction tx = sess.beginTransaction();
sess.saveOrUpdate(p);
tx.commit();
At this point, what if we
do an
sess.close();
update, via SQLPLUS?

See SAMPLE 0

4/4
copyright 2006, rhinosystemsinc.c
om all rights reserved
Code[0]: Java 1-to-Many
public class Person {
Long PERSON_ID=null; //manufactured surrogate key
String FIRST_NAME=null;
String LAST_NAME=null;
Set ADDRESSES=null;
public Set getADDRESSES()
{
return ADDRESSES;
} NEW
public void setADDRESSES(Set ADDRESSES)
{
this.ADDRESSES = ADDRESSES;
}
…//rest of get/set methods
}

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Person XML 1-to-Many

<hibernate-mapping>
<class name="com.rhinosystemsinc.hibernate.samples_0.Person" table="SAMPLE0_Person" >

<set
name="ADDRESSES"
lazy="false"
inverse="true"
all or save-update-delete
cascade="save-update"
sort="unsorted"
NEW
outer-join="true"> Any records that don't have address will be shown too.
<key column="PERSON_ID"/>
<one-to-many class="com.rhinosystemsinc.hibernate.samples_1.Address"/> Notice one-to-many ~
</set>

</class>
</hibernate-mapping>

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Java 1-to-Many
public class Address {
Long ADDRESS_ID=null; New Address class
String STREET=null;
String APT_NO=null;
String CITY=null;
String STATE=null;
Person reference ~
String ZIP=null;
Person person=null;// the person this address belongs to.
public Person getPerson()
{
return person;
}
public void setPerson(Person person)
{
this.person = person;
}
…//rest of get/set methods
}

See Sample 1 copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Address XML 1-to-Many
…usual header Address class
<class name="com.rhinosystemsinc.hibernate.samples_1.Address"
table="SAMPLE1_Address" dynamic-update="true">
<id name="ADDRESS_ID" column="ADDRESS_ID" NOTICE different
type="java.lang.Long" unsaved-value="null"> definition sample of
<generator class="sequence">
<param name="sequence">SAMPLE1_ADDRESS_SEQ</param>
the sequence
<param name="parameters">INCREMENT BY 1 START WITH 1</param>
</generator> Notice variable name in Address class
</id>
<many-to-one name="person" class="com.rhinosystemsinc.hibernate.samples_1.Person"
cascade="save-update" For outer-join fetching or use 'select'
fetch="join" sequential select fetching. N+1 select prob.
lazy="false" will always be
update="true" eagerly fetched.
insert="true" ~
column="PERSON_ID"
not-null="false"/>
…rest of properties defined

See Sample 1 copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: main 1-to-Many
public static void main(String args[])
….
Address addr = new Address();
Person p = new Person();
p.setFIRST_NAME("John");
p.setLAST_NAME("Thompson");
p.setADDRESSES(new HashSet()); Create an empty "set" and assign to Person
p.getADDRESSES().add(addr);
p.setCreated(new Date()); Add the address to the "set"
addr.setSTREET("12345 Easy");
addr.setCITY("Sacramento");
addr.setSTATE("CA");
addr.setORDER_POS(new Long(1));
addr.setCreated(new Date());
addr.setPerson(p); assign person reference to address ~

sess.save(p);
tx.commit();

See Sample 1 copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Java Many-to-Many
public class Address {
…same as before
Set persons=null;// the person this address belongs to.
public Set getPersons()
{
return persons;
} NEW ~
public void setPersons(Set persons)
{
this.persons = persons;
}

…//rest of get/set methods


}

See Sample 2 copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: XML Many-to-Many
…usual header
<class name=...Address> "Set persons=null" in java
<set name="persons"
table="SAMPLE2_PERSON_ADDRESS"> Intermediate M-M table
<key column="ADDRESS_ID"/>
<many-to-many M-M definition,
class="com.rhinosystemsinc.hibernate.samples_2.Person" referencing the Person
column="PERSON_ID"/> class by PERSON_ID
~
</set>
…rest of properties defined
</class>
</hibernate-mapping>

See Sample 1 copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Main Many-to-Many
Address addr = new Address();
Person p = new Person(); Setup empty Address and Person object
p.setFIRST_NAME("John");
p.setLAST_NAME("Thompson");
Create empty list of Addresses
p.setADDRESSES(new HashSet());
p.getADDRESSES().add(addr);
p.setCreated(new Date());
addr.setSTREET("12345 Easy");

//revised! for many-to-many
addr.setPersons(new HashSet());
addr.getPersons().add(p);
//ADD NEW PERSON TO ADDRESS
Martha also lives at the SAME address,
Person p2=new Person();
p2.setFIRST_NAME("Martha");
here we add the address to the p2 object ~

p2.setLAST_NAME("Thompson");
p2.setADDRESSES(new HashSet());
p2.getADDRESSES().add(addr);
addr.getPersons().add(p2);

See Sample 1 copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Reference Data
• Data that doesn't change usually loaded at system
installation time. (Use 2nd level Cache).
– Examples: STATES, CATEGORY, ZIP..etc.
• Strategy
– Setup XML class with element cache as read-only
– Setup cache for relation as read-only
– Call a method to load All read-only objects at
initialization (actually even everytime).
(for example…)

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Reference Data

<class name="com.rhinosystemsinc.sample.Event"> For the EVENT class

<many-to-one
name="CATEGORY" Variable name for java class
Category CATEGORY=null;
class="com.rhinosystemsinc.sample.Category"
cascade="none" which operations should be cascaded from
update="false" the parent object to the associated object
insert="false"
column="CATEGORY_ID" We will not update or insert from this relationship. ~
not-null="true" />
</class>

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code[0]: Reference Data
… For the CATEGORY class
<class name="com.rhinosystemsinc.sample.Category" mutable="false">
<cache usage="read-only" />
Set cache to be read-only

</class>
Also - notice no need for a reference back to Event class
----------------------------------------------------------------------------------------------------------
In your Java code, load the objects at least once…

org.hibernate.Query q = sess.createQuery("from Category");
q.setCacheMode(org.hibernate.CacheMode.NORMAL);
q.setCacheable(true);
java.util.List result = q.list(); Make sure your Query sets up the CACHING! (2 nd level) ~

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Components
• Components
"Fine-grained object Model" - more Classes than Tables
– Value Type – not Entity reference
• Meaning, you want separate Java class (from the main entity)
for this property, and yet it is stored in DB with main entity
• Lets Consider ZIP_CODE as example.
• Address w/ ZipCode attribute
• ZipCode defines ZIP_CODE and ZIP_4DIGIT_CODE as fields
• Address Table has two fields in table (w/ same field names).

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Component (example)
//JAVA ADDRESS CLASS:
public class Address {
… ZipCode variable, name is same as
ZipCode ZIP=null; mapping below.
public ZipCode getZIP(){…}
public void setZIP(ZipCode ZIP)
}
//Address.hbm.xml ------------------------------------------------------------------------------------------
…usual header
<class name="com.rhinosystemsinc.hibernate.samples_3.Address" Notice use of "component", with class
table="SAMPLE3_Address" dynamic-update="true">
name ~

<component name="ZIP" class="com.rhinosystemsinc.hibernate.samples_3.ZipCode">

</class>

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Component (example)
//Java ZipCode Class
public class ZipCode { NO ID
// Components have NO ID...they are just entirely dependent on
// containing Entity - in this case Address - in otherwords,
// we want a Java Class representation of ZipCode, but want it
// mapped into the Address table with ZIP_CODE and ZIP_4DIGIT_CODE Two attributes
// as attributes of Address table. w/
String ZIP_CODE = ""; getters/setters
String ZIP_4DIGIT_CODE = "";
public String getZIP_4DIGIT_CODE(){…}
public void setZIP_4DIGIT_CODE(String ZIP_4DIGIT_CODE){…}
public String getZIP_CODE(){…}
public void setZIP_CODE(String ZIP_CODE){…}
}
In this example: Attribute names map directly to database column names ~

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Component (example)
//SQL for Address table:
create table SAMPLE3_Address
(
ADDRESS_ID number primary key,
STREET varchar2(512),
APT_NO varchar2(64),
CITY varchar2(512),
STATE varchar2(2),
ZIP_CODE varchar2(5), Notice same name as
ZIP_4DIGIT_CODE varchar2(4) ZipCode variables. ~
);

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Component (example)
//Java Main Code
Address addr = new Address();
Person p = new Person(); Usual initialization here.
p.setFIRST_NAME("John");
p.setADDRESSES(new HashSet());
p.getADDRESSES().add(addr);
addr.setSTREET("12345 Easy");

ZipCode zip=new ZipCode();
zip.setZIP_CODE("95603"); Create a ZipCode
zip.setZIP_4DIGIT_CODE("4456"); object, initialize it, and
addr.setZIP(zip); set to the Address
addr.setPersons(new HashSet());
addr.getPersons().add(p);
Note: query returns an Address object w/

ZipCode filled in automatically. ~
sess.saveOrUpdate(p);

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Querying

• Hibernate offers a variety of ways to query


the objects:
– SQL – straight SQL (parsed SQL 92 standard)
– HQL – hibernate's query language (SQL based)
– QBE – query by example
– Criteria Queries – Object oriented

copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Querying
Use the session to create the Query
object.
• HQL simple example:
Query q = sess.createQuery("from Person");
java.util.List result = q.list(); Can also use ? As positional param
// ALSO Then use:
q.setString(0, First);
Query q = sess.createQuery("from Person q.setString(1,
p where " +Last);
"p.FIRST_NAME = :fname and " +
"p.LAST_NAME =:lname");
q.setString("fname", First); //can also use positional parameters
q.setString("lname", Last); Returns a list, that you can iterate
through and cast the "objects" to
java.util.List result = q.list(); Person. ~

See all examples for quering copyright 2006, rhinosystemsinc.c


om all rights reserved
Code: Querying
• HQL scalar example (from reference.pdf):
Iterator results = sess.createQuery(
"select cat.color, min(cat.birthdate), count(cat) from Cat cat " +
"group by cat.color").list().iterator();
while ( results.hasNext() )
{ Notice alias "cat" lowercase
Object[] column = (Object[]) results.next();
Color type = (Color) column[0]; Notice cast – same as attribute
Date oldest = (Date) column[1]; declared in Cat class ~
Integer count = (Integer) column[2];
.....
}

See all examples for quering


copyright 2006, rhinosystemsinc.c
om all rights reserved
Code: SQL Querying
• SQL example: createSQLQuery
org.hibernate.SQLQuery q = sess.createSQLQuery("select * " +
" from SAMPLE0_PERSON" +
" where " +
" FIRST_NAME = :fname " +
" and LAST_NAME = :lname");
q.addEntity(Person.class);
q.setString("fname", First); //can also use positional parameters
q.setString("lname", Last); Tell hibernate about actual
java.util.List result = q.list(); class

Bind parameters ~

See all examples for quering


copyright 2006, rhinosystemsinc.c
om all rights reserved
Code: SQL Querying
• SQL example #2: With Alias

org.hibernate.SQLQuery q = sess.createSQLQuery("select {Person.*} " +


" from SAMPLE0_PERSON Person where " +
" Person.FIRST_NAME = :fname " +
" and Person.LAST_NAME =:lname");
q.addEntity("Person",Person.class);
q.setString("fname", First); //can also use positional parameters
q.setString("lname", Last); See also:
java.util.List result = q.list(); q.addScalar(String columnAlias, Type type).

… q.addJoin(String alias, String path). Where path is the


path to the java collection member variable name of the
parent class. In our example it would be
"Person.ADDRESSES" ~

See all examples for quering


copyright 2006, rhinosystemsinc.c
om all rights reserved
Pros/Cons
• Cons
– Lots of idiosyncrasies. – caching, flushing,
inverse…etc. (But can configure/disable them.)
– Learning curve is fairly steep.
(learn a way and stick with it).
– Not good for bulk-inserts (batch processing)
(forced to use PL/SQL within hibernate or jdbc)
– Java-XML-table all defining entity (good and
bad) – (xdoclet and other tools – setup system of generating base/core
code elements – use patterns and conventions)

copyright 2006, rhinosystemsinc.c


om all rights reserved
Pros/Cons
• Pros
– Simple to understand concepts.
– Stick with tools and frameworks, then can speed up
development time.
– Caching for you – so better performance.
(if you don’t use cache, then similar to straight SQL w/ preparedstatement performance).
– Highly extensible and customizable to suite your needs for
new development and conversion.
– Defacto standard, via OpenSource LGPL license, non
proprietary, and known by developer community
(cost, maintenance, bugs..etc.)

copyright 2006, rhinosystemsinc.c


om all rights reserved
Resources

• Hibernate.org – is the best most up-to-date


– FAQs : http://www.hibernate.org/5.html
• Advanced Problems, Tips and Tricks, Performance and more…
• Evaluation- http://www.hibernate.org/263.html
– Doc link: http://www.hibernate.org/5.html
– Migration (A MUST!) – http://www.hibernate.org/250.html
• Package change: net.sf -> org.hibernate
• SessionFactory
• Criteria Query

copyright 2006, rhinosystemsinc.c


om all rights reserved
Resources

• Hibernate installation
– <installdir>/doc/
{api,other,reference}/en/pdf/hibernate_reference.pdf (great for
reference, yet not sufficient for beginners to "learn").
– <installdir>/eg – samples

copyright 2006, rhinosystemsinc.c


om all rights reserved
Resources

• Miscellaneous
– Book: Hibernate In Action http://www.manning.com/bauer
– Performance #'s:
http://www.sourcelabs.com/?sidemenu=3&page=software&sub=sash_hibernateperftest
• Hibernate user FORUM - http://forum.hibernate.org/
(+200 msg/day)
• CaveatEmptor Sample from Hibernate:
http://caveatemptor.hibernate.org/

copyright 2006, rhinosystemsinc.c


om all rights reserved
End 0f Presentation

Thank you!
• Extra topics session follow, if time.
~ Or ~
• Q&A
• Future Questions:
email: joel@rhinosystemsinc.com

copyright 2006, rhinosystemsinc.c


om all rights reserved
XDoclet

• XDoclet is used to generate hibernate XML


files.
– You specify annotation tags in your Java code
– Run an xdoclet-ANT task on the java code
– Make sure xml is in your classpath (the
xdoclet-ant will put in src directory)
• Hibernate Annotations, next step.
See all examples of Xdoclet in the java code
copyright 2006, rhinosystemsinc.c
om all rights reserved
XDoclet example

• Person.java • Person.hbm.xml
Long PERSON_ID=null; <id name="PERSON_ID"

String FNAME=null; Xdoclet Ant column="PERSON_ID"


type="java.lang.Long"
/** @hibernate.id
/** @hibernate.id task unsaved-value="null">
<generator class="sequence">
** unsaved-value="null"
unsaved-value="null"
<!– …some xdoclet commentary…-->
** generator-class="sequence"*/
generator-class="sequence"*/ </generator>
public Long get
getPERSON_ID(){} </id>
<property
public void setPERSON_ID(Long){} name="LAST_NAME"
/** @hibernate.property */
/** @hibernate.property */ type="java.lang.String"
update="true"
public String getFNAME(){} insert="true"
column="LAST_NAME"
public void setFNAME(String){} />

•Maintain tags in one location - Java


•On building (one click) create hbm.xml files

See all examples for xdoclet copyright 2006, rhinosystemsinc.c


om all rights reserved
Topics Not Covered
• SessionFactory • Session and Flushing
• PLSQL – Session "unit of work"
• Custom UserType • Interceptors & Logging
• Caching (1st & 2nd Level) • Definitions:
• – Transient, Persistent,
Transactions and
Detached
Isolation Levels
– JDBC trx semantics • Subclass
– Concurrent Updates and
versioning.

copyright 2006, rhinosystemsinc.c


om all rights reserved

S-ar putea să vă placă și