SlideShare a Scribd company logo
1 of 37
doubleSlash  Net-Business GmbH  Rainer Müller Fon 07541/6047-100 Müllerstr. 12 B D-88045 Friedrichshafen http://doubleSlash.de » Java-Persistenz mit Hibernate « Technology Days 2007 - Workshop
» Inhalt « ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
» Once upon a time « ,[object Object],[object Object],[object Object],public void addPerson(Person person) throws PersistenceException { Connection con = null; PreparedStatement pstmt = null; String str = ""; str += "insert into person "; str += "(id, lastname, age) "; str += "values (?, ?, ?)"; try { try { con = DriverManager.getConnection( this.dbUrl, this.dbUser, this.dbPwd); pstmt = con.prepareStatement(str); pstmt.setQueryTimeout(QUERYTIMEOUT); pstmt.setString(1, person.getId()); pstmt.setString(2, person.getLastName()); pstmt.setInt  (3, person.getAge()); pstmt.executeUpdate(); } finally { if (pstmt != null) pstmt.close(); if (con != null) con.close(); } } catch (SQLException se) { PersistenceException e = new PersistenceException( PersistenceException.ERROR, ME, METHOD, se); e.addDescription("Last SQL-statement: " + str); throw e; } } Wie wurde Persistenz in typischen Java-Anwendungen bisher gehandhabt? Hinweis : Nebenstehendes Beispiel ist sehr ineffizient bezüglich Performance, da für die Insert-Operation eine eigene Connection verwendet wird.
» Was ist Hibernate? « ,[object Object],[object Object],[object Object],[object Object]
»Vorteile« ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
»Nachteile« ,[object Object],[object Object]
» Architektur von Hibernate « Nebenstehendes Schaubild zeigt die Architektur von Hibernate. ,[object Object],[object Object],[object Object],Als Anwendungsentwickler hat man in der Regel mit folgenden Komponenten bzw. Objekten zu tun: Über die  SessionFactory  erhält man eine  Session . Darüber wird eine  Transaction  gestartet, in der man seine Operationen durchführt.
» Objektdefinitionen (1) « ,[object Object],[object Object]
» Objektdefinitionen (2) « ,[object Object]
»Objektdefinitionen (3)« ,[object Object],[object Object],[object Object]
»Persistenz- Lebenszyklus «
» Ein einfaches Beispiel – Datenbankschema« ,[object Object],Nebenstehend ist das zu unserem einfachen Beispiel zugehörige Datenbank-Schema zu sehen. Dass es im Rahmen dieses Beispiels zu allererst gezeigt wird muss nicht bdeuten, dass es zu allererst erstellt werden muss (siehe „Verfahrensweisen“).
» Ein einfaches Beispiel – Objektklassen (1) « ,[object Object],[object Object],[object Object],[object Object],package de.doubleslash.demo.model public class Person { private Integer id; private String name; private Set<Address> addresses; public Person() {} public Integer getId() { return this.id; } protected void setId(Integer id) { this.id = id; } public String getName() { return this.name; } public void setName(String name) { this.firstName = firstName; } ...
» Ein einfaches Beispiel – Objektklassen (2)  « ,[object Object],[object Object],[object Object],... public Set<Address> getAddresses() { return this.addresses; } protected void setAddresses(Set<Address> adresses) { this.addresses = addresses; } public void addAddress(Address address) { if (address == null) { throw new IllegalArgumentException( &quot;Address is null!&quot;); } this.addresses.add(address); } public void removeAddress(Address address) { if (address == null) { throw new IllegalArgumentException( &quot;Address is null!&quot;); } if (!this.addresses.remove(address)) { throw new IllegalArgumentException( &quot;Address is not assigned!&quot;); } } }
» Ein einfaches Beispiel – Objektklassen (3)  « ,[object Object],package de.doubleslash.demo.model public class Address { private Integer id; private String zip; private String city; public Address() {} public Integer getId() { return this.id; } protected void setId(Integer id) { this.id = id; } public String getZip() { return this.zip; } public void setZip(String zip) { this.zip = zip; } // + Getter / Setter fuer city }
» Ein einfaches Beispiel – XML Mapping « ,[object Object],<?xml version=&quot;1.0&quot;?> <!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;> <hibernate-mapping package=&quot;de.doubleslash.demo.model&quot;> <class name=&quot;Person&quot; table=&quot;person&quot;> <id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;> <generator class=&quot;native&quot;/> </id> <!– object attribut name --> <property name=&quot;name&quot; type=&quot;string&quot; column=&quot;name&quot;/> <!-- uni-directional one-to-many association to Address --> <set name=&quot;addresses&quot; table=&quot;address&quot; access=&quot;field&quot; cascade=&quot;save-update, delete&quot; > <key column=&quot;personid&quot; not-null=&quot;true&quot;/> <one-to-many class=&quot;Address&quot;/> </set> </class> </hibernate-mapping> <?xml version=&quot;1.0&quot;?> <!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;> <hibernate-mapping package=&quot;de.doubleslash.demo.model&quot;> <class name=&quot;Address&quot; table=&quot;address&quot;> <id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;> <generator class=&quot;native&quot;/> </id> <property name=&quot;zip&quot; type=&quot;string&quot; column=&quot;zip&quot;/> <property name=&quot;city&quot; type=&quot;string&quot; column=&quot;city&quot;/> </class> </hibernate-mapping>
» Ein einfaches Beispiel – Hibernate Konfigurationsdatei « <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <!DOCTYPE hibernate-configuration PUBLIC &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name=&quot;hibernate.connection.driver_class&quot;>com.mysql.jdbc.Driver</property> <property name=&quot;hibernate.connection.url&quot;>jdbc:mysql://horizon:3306/demodb</property> <property name=&quot;hibernate.connection.username&quot;>user</property> <property name=&quot;hibernate.connection.password&quot;>geheim</property> <!-- SQL dialect --> <property name=&quot;hibernate.dialect&quot;>org.hibernate.dialect.MySQLInnoDBDialect</property> <!-- JDBC connection pool (built-in) --> <!--property name=&quot;connection.pool_size&quot;>10</property--> <!-- Disable the second-level cache --> <property name=&quot;cache.provider_class&quot;>org.hibernate.cache.NoCacheProvider</property> <!-- Enable Hibernate's automatic session context management --> <property name=&quot;current_session_context_class&quot;>thread</property> <!-- Mapping files --> <mapping resource=&quot;Person.hbm.xml&quot;/> <mapping resource=&quot;Address.hbm.xml&quot;/> </session-factory> </hibernate-configuration>
» Ein einfaches Beispiel - HibernateUtil « ,[object Object],[object Object],package de.doubleslash.demo.util; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtil { private static SessionFactory sessionFactory; private static Configuration configuration; static { try { configuration = new Configuration(); sessionFactory = configuration.configure() .buildSessionFactory(); } catch (Throwable t) { log.error(&quot;Build of SessionFactory failed.&quot;, t); throw new ExceptionInInitializerError(t); } } public static SessionFactory getSessionFactory() { return sessionFactory; } }
»  Ein einfaches Beispiel - Speichern « ,[object Object],public class StoreDemo { public static void main(String[] args) { Address address = new Address(); address.setZip(&quot;88045&quot;); address.setCity(&quot;Friedrichshafen&quot;); Person person = new Person(); person.setName(&quot;Müller&quot;); person.addAddress(address); SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); session.save(person);  // Person & Address -> DB tx.commit(); } catch (Exception e) { rollback(tx); } } } Es ist soweit: Die eigentliche Anwendung kann implementiert werden. Wir werden uns im weiteren Verlauf die Operationen  speichern ,  lesen ,  ändern  und  löschen  für unsere zuvor erstellten Objekte  Person  und  Address  ansehen. Zu Demonstrationszwecken werden dabei direkt die Methoden der  Session  verwendet, welche üblicherweise in einer DAO-Klasse weggekapselt sind. Zudem wird das Exception-Handling vereinfacht dargestellt.
»  Ein einfaches Beispiel - Lesen « ,[object Object],[object Object],[object Object],package de.doubleslash.demo; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; public class ReadDemo { public static void main(String[] args) { SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); Person person = session.get(Person.class, 1); Set<Address> addresses = person.getAddresses(); tx.commit(); } catch (Exception e) { rollback(tx); } } }
»  Ein einfaches Beispiel - Ändern « ,[object Object],[object Object],[object Object],public class ChangeDemo { public static void main(String[] args) { SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); Person person = session.get(Person.class, 1); person.setName(&quot;Meier&quot;); Address address = person.getAddresses().get(0); address.setZip(&quot;88046&quot;); session.saveOrUpdate(person); tx.commit(); } catch (Exception e) { rollback(tx); } } }
»  Ein einfaches Beispiel - Löschen « ,[object Object],[object Object],[object Object],public class DeleteDemo { public static void main(String[] args) { SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); Person person = session.get(Person.class, 1); session.delete(person); tx.commit(); } catch (Exception e) { rollback(tx); } } }
»  Ein einfaches Beispiel – Query mittels HQL « ,[object Object],[object Object],[object Object],[object Object],public class HqlDemo { public static void main(String[] args) { SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; Query query = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); query = session.createQuery(&quot;from Person p&quot; + &quot;where p.address.city = :city&quot;); query.setString(&quot;Friedrichshafen&quot;); List<Person> persons = query.list(); tx.commit(); } catch (Exception e) { rollback(tx); } } }
»  Ein einfaches Beispiel – Query mittels Criteria « ,[object Object],[object Object],[object Object],public class ExampleDemo { public static void main(String[] args) { SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; Criteria crit = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); crit = session.createCriteria(Person.class); crit.createCriteria(Address.class) .add(Restrictions.like(&quot;city&quot;, &quot;%hafen&quot;)); List<Person> persons = crit.list(); tx.commit(); } catch (Exception e) { rollback(tx); } } }
»  Ein einfaches Beispiel – Query mittels Example « ,[object Object],[object Object],[object Object],[object Object],public class ExampleDemo { public static void main(String[] args) { SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; Criteria crit = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); Address address = new Address(); address.setCity(&quot;Friedrichshafen&quot;); Example example = Example.create(address); crit = session.createCriteria(Person.class); crit.createCriteria(&quot;address&quot;).add(example); List<Person> persons = crit.list(); tx.commit(); } catch (Exception e) { rollback(tx); } } }
» Exception Handling « ,[object Object],[object Object],[object Object],SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = null; Transaction tx = null; try { session = sf.openSession(); tx = session.beginTransaction(); // do something tx.commit(); } catch (RuntimeException e) { try { tx.rollback(); } catch (RuntimeException ex) { log.error(&quot;Couldn't roll back transaction&quot;, ex); } throw ex; } finally { session.close(); }
» Fallstrick Lazy-Initialisierung (1) « ,[object Object],[object Object],[object Object],SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = null; Transaction tx = null; PersonDAO dao = DAOFactory.getPersonDAO(); Person person = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); person = dao.getPerson(4711); tx.commit(); } catch (Exception e) { rollback(tx); } person.getAddress();  // <- LazyInitialisationException Ein klassischer Fehler bei Hibernate-Anwendungen ist das Auftreten einer  LazyInitialisationException . public class Person { private Integer id; private String name; private Address address; public Address getAddress() { return this.address; } }
» Fallstrick Lazy-Initialisierung (2) « SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; PersonDAO dao = DAOFactory.getPersonDAO(); Person person = null; Address address = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); person = dao.getPerson(4711); Hibernate.initialize(person.getAddress()); tx.commit(); } catch (Exception e) { rollback(tx); } person.getAddress(); // <- keine Exception address.getStreet(); // <- keine Exception Lösungsmöglichkeit 1 : Lösungsmöglichkeit 2 : SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; PersonDAO dao = DAOFactory.getPersonDAO(); Person person = null; Address address = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); person = dao.getPerson(4711); address = person.getAddress();  // <- keine // Exception tx.commit(); } catch (Exception e) { rollback(tx); } address.getStreet(); // <- keine Exception
» Fallstrick Lazy-Initialisierung (3) « ,[object Object],Weitere Möglichkeit : ,[object Object],[object Object],[object Object],Weitere Möglichkeiten die damit in Zusammenhang stehen, jedoch primär auf Performance-Optimierung ausgerichtet sind :
» Fallstrick Verhalten der Session (1) « ,[object Object],[object Object],[object Object],SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = null; Transaction tx = null; PersonDAO dao = DAOFactory.getPersonDAO(); Set<Person> persons = null; List<Integer> allIds = null; List<Integer> someIds = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); allIds = dao.getAllPersonIds(); // <- 30.000 Stück int count = (int) Math.ceil(allIds.size() / 100); for (int i=0; i<count; i++) { someIds = getSomeIds(allIds, i, 100); // 100 Stück persons = dao.getPersonsByIds(someIds); exportToExcel(persons); } tx.commit(); } catch (Exception e) { rollback(tx); } Ein weiterer Fallstrick bei Hibernate-Anwendungen ist die standardmässige Verhaltensweise der  Session .
» Fallstrick Verhalten der Session (2) « ,[object Object],[object Object],[object Object],SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = null; Transaction tx = null; PersonDAO dao = DAOFactory.getPersonDAO(); Set<Person> persons = null; List<Integer> allIds = null; List<Integer> someIds = null; try { session = sf.getCurrentSession(); session.setFlushMode(FlushMode.MANUAL); // <- Lösung tx = session.beginTransaction(); allIds = dao.getAllPersonIds(); // <- 30.000 Stück int count = (int) Math.ceil(allIds.size() / 100); for (int i=0; i<count; i++) { someIds = getSomeIds(allIds, i, 100); // 100 Stück persons = dao.getPersonsByIds(someIds); exportToExcel(persons); session.clear(); // <- Lösung } tx.commit(); } catch (Exception e) { rollback(tx); } Eine mögliche Lösung kann wie in nebenstehendem Beispiel gezeigt aussehen.
»Tools und  Vorgehensweisen « ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
» Vorgehensweise   Top down « ,[object Object],[object Object],public class Person { private Integer id; private String firstName; private String lastName; private int age; // Getter-/Setter Methoden } <?xml version=&quot;1.0&quot;?> <!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;> <hibernate-mapping package=&quot;de.doubleslash.demo.model&quot;> <class name=&quot;Person&quot; table=&quot;person&quot;> <id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;> <generator class=&quot;native&quot;/> </id> <property name=&quot;firstName&quot; type=&quot;string&quot; column=&quot;firstname&quot; length=&quot;30&quot;/> <property name=&quot;lastName&quot; type=&quot;string&quot; column=&quot;lastname&quot; length=&quot;30&quot; not-null=&quot;true&quot;/> <property name=&quot;age&quot; type=&quot;integer&quot; column=&quot;age&quot;/> </class> </hibernate-mapping> ,[object Object],CREATE TABLE person ( id  INTEGER NOT NULL AUTO_INCREMENT, firstname  VARCHAR(30), lastname  VARCHAR(30) NOT NULL, age  INTEGER ); ,[object Object]
» Vorgehensweise Bottom up  « ,[object Object],[object Object],public class Person { private Integer id; private String firstName; private String lastName; private int age; // Getter-/Setter Methoden } <?xml version=&quot;1.0&quot;?> <!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;> <hibernate-mapping package=&quot;de.doubleslash.demo.model&quot;> <class name=&quot;Person&quot; table=&quot;person&quot;> <id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;> <generator class=&quot;native&quot;/> </id> <property name=&quot;firstName&quot; type=&quot;string&quot; column=&quot;firstname&quot; length=&quot;30&quot;/> <property name=&quot;lastName&quot; type=&quot;string&quot; column=&quot;lastname&quot; length=&quot;30&quot; not-null=&quot;true&quot;/> <property name=&quot;age&quot; type=&quot;integer&quot; column=&quot;age&quot;/> </class> </hibernate-mapping> ,[object Object],CREATE TABLE person ( id  INTEGER NOT NULL AUTO_INCREMENT, firstname  VARCHAR(30), lastname  VARCHAR(30) NOT NULL, age  INTEGER ); ,[object Object],[object Object]
» Vorgehensweise Middle out « ,[object Object],[object Object],public class Person { private Integer id; private String firstName; private String lastName; private int age; // Getter-/Setter Methoden } <?xml version=&quot;1.0&quot;?> <!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;> <hibernate-mapping package=&quot;de.doubleslash.demo.model&quot;> <class name=&quot;Person&quot; table=&quot;person&quot;> <id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;> <generator class=&quot;native&quot;/> </id> <property name=&quot;firstName&quot; type=&quot;string&quot; column=&quot;firstname&quot; length=&quot;30&quot;/> <property name=&quot;lastName&quot; type=&quot;string&quot; column=&quot;lastname&quot; length=&quot;30&quot; not-null=&quot;true&quot;/> <property name=&quot;age&quot; type=&quot;integer&quot; column=&quot;age&quot;/> </class> </hibernate-mapping> CREATE TABLE person ( id  INTEGER NOT NULL AUTO_INCREMENT, firstname  VARCHAR(30), lastname  VARCHAR(30) NOT NULL, age  INTEGER ); ,[object Object],[object Object]
» Vorgehensweise Meet in the middle « ,[object Object],[object Object],public class Person { private Integer id; private String firstName; private String lastName; private int age; // Getter-/Setter Methoden } <?xml version=&quot;1.0&quot;?> <!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;> <hibernate-mapping package=&quot;de.doubleslash.demo.model&quot;> <class name=&quot;Person&quot; table=&quot;person&quot;> ??? <!– Abhaengig von den Refaktorierungsmassnahmen --> </class> </hibernate-mapping> ,[object Object],CREATE TABLE employee ( name  VARCHAR(50) NOT NULL, gender  INTEGER NOT NULL, birthdate  DATE NOT NULL, salary  NUMBER(7,2) NOT NULL ); ,[object Object]
Ihr IT-Partner für  individuelle Softwarelösungen doubleSlash Net-Business GmbH  Müllerstr. 12 B / D-88045 Friedrichshafen http://doubleSlash.de  / info@doubleSlash.de Herzlichen Dank für Ihr  Interesse.

More Related Content

Viewers also liked

Maisons Hervé - Constructeur de maisons individuelles
Maisons Hervé - Constructeur de maisons individuelles Maisons Hervé - Constructeur de maisons individuelles
Maisons Hervé - Constructeur de maisons individuelles Groupe Diogo Fernandes
 
Marc & Rhénatic
Marc & RhénaticMarc & Rhénatic
Marc & RhénaticDiane Geng
 
1m mb 4_national_geographic
1m mb 4_national_geographic1m mb 4_national_geographic
1m mb 4_national_geographicfotoaik
 
Création de carte
Création de carteCréation de carte
Création de carteEPN Gouvy
 
Magritte
MagritteMagritte
MagritteJDP
 
Catalogue produits Babymoov 2012
Catalogue produits Babymoov 2012Catalogue produits Babymoov 2012
Catalogue produits Babymoov 2012Romu
 
Presentaciones sesion7
Presentaciones sesion7Presentaciones sesion7
Presentaciones sesion7Alejandro Caro
 
Créer un site internet professionnel-Oolongmedia.ca
Créer un site internet professionnel-Oolongmedia.ca Créer un site internet professionnel-Oolongmedia.ca
Créer un site internet professionnel-Oolongmedia.ca Oolong Media
 
2010 04 01 Lock Schuppen Co Working
2010 04 01 Lock Schuppen Co Working2010 04 01 Lock Schuppen Co Working
2010 04 01 Lock Schuppen Co WorkingRalf Lippold
 
Tony Rodríguez. Resurrección de mi matrimonio a la vida comunitaria
Tony Rodríguez. Resurrección de mi matrimonio a la vida comunitariaTony Rodríguez. Resurrección de mi matrimonio a la vida comunitaria
Tony Rodríguez. Resurrección de mi matrimonio a la vida comunitariainfocatolicos
 
Quejas contra Dios - José Luis Caravias, sj.
Quejas contra Dios - José Luis Caravias, sj.Quejas contra Dios - José Luis Caravias, sj.
Quejas contra Dios - José Luis Caravias, sj.infocatolicos
 
AdsRadios Présentation- 19 sept 2012
AdsRadios Présentation- 19 sept 2012AdsRadios Présentation- 19 sept 2012
AdsRadios Présentation- 19 sept 2012AdsWizz
 
Twitter : Késako ?
Twitter : Késako ? Twitter : Késako ?
Twitter : Késako ? Aurore Widmer
 
50 euros c'est 50 euros
50 euros c'est 50 euros50 euros c'est 50 euros
50 euros c'est 50 eurossandre07
 
CCI LVN - Coaching énergie 2013
CCI LVN - Coaching énergie 2013CCI LVN - Coaching énergie 2013
CCI LVN - Coaching énergie 2013CCICONNECT
 
Ignacianos enviados a las fronteras - José Luis Caravias, sj.
Ignacianos enviados a las fronteras - José Luis Caravias, sj.Ignacianos enviados a las fronteras - José Luis Caravias, sj.
Ignacianos enviados a las fronteras - José Luis Caravias, sj.infocatolicos
 

Viewers also liked (20)

Maisons Hervé - Constructeur de maisons individuelles
Maisons Hervé - Constructeur de maisons individuelles Maisons Hervé - Constructeur de maisons individuelles
Maisons Hervé - Constructeur de maisons individuelles
 
Marc & Rhénatic
Marc & RhénaticMarc & Rhénatic
Marc & Rhénatic
 
1m mb 4_national_geographic
1m mb 4_national_geographic1m mb 4_national_geographic
1m mb 4_national_geographic
 
Création de carte
Création de carteCréation de carte
Création de carte
 
Magritte
MagritteMagritte
Magritte
 
Catalogue produits Babymoov 2012
Catalogue produits Babymoov 2012Catalogue produits Babymoov 2012
Catalogue produits Babymoov 2012
 
Encuesta
EncuestaEncuesta
Encuesta
 
Presentaciones sesion7
Presentaciones sesion7Presentaciones sesion7
Presentaciones sesion7
 
Créer un site internet professionnel-Oolongmedia.ca
Créer un site internet professionnel-Oolongmedia.ca Créer un site internet professionnel-Oolongmedia.ca
Créer un site internet professionnel-Oolongmedia.ca
 
23 octobre 2011 renens
23 octobre 2011 renens23 octobre 2011 renens
23 octobre 2011 renens
 
2010 04 01 Lock Schuppen Co Working
2010 04 01 Lock Schuppen Co Working2010 04 01 Lock Schuppen Co Working
2010 04 01 Lock Schuppen Co Working
 
Scribus
ScribusScribus
Scribus
 
Tony Rodríguez. Resurrección de mi matrimonio a la vida comunitaria
Tony Rodríguez. Resurrección de mi matrimonio a la vida comunitariaTony Rodríguez. Resurrección de mi matrimonio a la vida comunitaria
Tony Rodríguez. Resurrección de mi matrimonio a la vida comunitaria
 
Quejas contra Dios - José Luis Caravias, sj.
Quejas contra Dios - José Luis Caravias, sj.Quejas contra Dios - José Luis Caravias, sj.
Quejas contra Dios - José Luis Caravias, sj.
 
AdsRadios Présentation- 19 sept 2012
AdsRadios Présentation- 19 sept 2012AdsRadios Présentation- 19 sept 2012
AdsRadios Présentation- 19 sept 2012
 
Twitter : Késako ?
Twitter : Késako ? Twitter : Késako ?
Twitter : Késako ?
 
50 euros c'est 50 euros
50 euros c'est 50 euros50 euros c'est 50 euros
50 euros c'est 50 euros
 
22 avril 2012
22 avril 201222 avril 2012
22 avril 2012
 
CCI LVN - Coaching énergie 2013
CCI LVN - Coaching énergie 2013CCI LVN - Coaching énergie 2013
CCI LVN - Coaching énergie 2013
 
Ignacianos enviados a las fronteras - José Luis Caravias, sj.
Ignacianos enviados a las fronteras - José Luis Caravias, sj.Ignacianos enviados a las fronteras - José Luis Caravias, sj.
Ignacianos enviados a las fronteras - José Luis Caravias, sj.
 

Similar to Workshop zu Hibernate 3.2.2 GA

Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...GFU Cyrus AG
 
Fundamentale Muster in Java
Fundamentale Muster in JavaFundamentale Muster in Java
Fundamentale Muster in Javatutego
 
2009 03 17 Spring101
2009 03 17 Spring1012009 03 17 Spring101
2009 03 17 Spring101gueste4be40
 
Jakarta EE 10: Ein erster Blick auf Eclipse JNoSQL
Jakarta EE 10: Ein erster Blick auf Eclipse JNoSQLJakarta EE 10: Ein erster Blick auf Eclipse JNoSQL
Jakarta EE 10: Ein erster Blick auf Eclipse JNoSQLgedoplan
 
Datenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence ApiDatenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence ApiChristian Baranowski
 
Warum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi steheWarum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi steheSven Ruppert
 
SOLID Prinzipien, Designgrundlagen objektorientierter Systeme
SOLID Prinzipien, Designgrundlagen objektorientierter SystemeSOLID Prinzipien, Designgrundlagen objektorientierter Systeme
SOLID Prinzipien, Designgrundlagen objektorientierter SystemeMario Rodler
 
Java Persistence in Action – Einsatz von JPA 2.x in Java-EE-Anwendungen
Java Persistence in Action – Einsatz von JPA 2.x in Java-EE-AnwendungenJava Persistence in Action – Einsatz von JPA 2.x in Java-EE-Anwendungen
Java Persistence in Action – Einsatz von JPA 2.x in Java-EE-Anwendungengedoplan
 
Einführung in nosql // ArangoDB mit Symfony 2
Einführung in nosql // ArangoDB mit Symfony 2Einführung in nosql // ArangoDB mit Symfony 2
Einführung in nosql // ArangoDB mit Symfony 2ArangoDB Database
 
Doctrine 2 - An Introduction (German)
Doctrine 2 - An Introduction (German)Doctrine 2 - An Introduction (German)
Doctrine 2 - An Introduction (German)Michael Romer
 
Einstieg In Oop
Einstieg In OopEinstieg In Oop
Einstieg In Oopflashdev
 
Speeding up Java Persistence
Speeding up Java PersistenceSpeeding up Java Persistence
Speeding up Java Persistencegedoplan
 
Migration auf die OBIEE - OPITZ CONSULTING - Till Sander
Migration auf die OBIEE - OPITZ CONSULTING - Till SanderMigration auf die OBIEE - OPITZ CONSULTING - Till Sander
Migration auf die OBIEE - OPITZ CONSULTING - Till SanderOPITZ CONSULTING Deutschland
 
The Lotus Code Cookbook
The Lotus Code CookbookThe Lotus Code Cookbook
The Lotus Code CookbookUlrich Krause
 
Feige sein! Testen im Java-EE-Umfeld
Feige sein! Testen im Java-EE-UmfeldFeige sein! Testen im Java-EE-Umfeld
Feige sein! Testen im Java-EE-Umfeldgedoplan
 
Legacy Code refaktorisieren
Legacy Code refaktorisierenLegacy Code refaktorisieren
Legacy Code refaktorisierenHendrik Lösch
 

Similar to Workshop zu Hibernate 3.2.2 GA (20)

Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
 
Fundamentale Muster in Java
Fundamentale Muster in JavaFundamentale Muster in Java
Fundamentale Muster in Java
 
2009 03 17 Spring101
2009 03 17 Spring1012009 03 17 Spring101
2009 03 17 Spring101
 
Jakarta EE 10: Ein erster Blick auf Eclipse JNoSQL
Jakarta EE 10: Ein erster Blick auf Eclipse JNoSQLJakarta EE 10: Ein erster Blick auf Eclipse JNoSQL
Jakarta EE 10: Ein erster Blick auf Eclipse JNoSQL
 
Datenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence ApiDatenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence Api
 
react-de.pdf
react-de.pdfreact-de.pdf
react-de.pdf
 
Warum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi steheWarum ich so auf das c von cdi stehe
Warum ich so auf das c von cdi stehe
 
TDD für Testmuffel
TDD für TestmuffelTDD für Testmuffel
TDD für Testmuffel
 
SOLID Prinzipien, Designgrundlagen objektorientierter Systeme
SOLID Prinzipien, Designgrundlagen objektorientierter SystemeSOLID Prinzipien, Designgrundlagen objektorientierter Systeme
SOLID Prinzipien, Designgrundlagen objektorientierter Systeme
 
Java Persistence in Action – Einsatz von JPA 2.x in Java-EE-Anwendungen
Java Persistence in Action – Einsatz von JPA 2.x in Java-EE-AnwendungenJava Persistence in Action – Einsatz von JPA 2.x in Java-EE-Anwendungen
Java Persistence in Action – Einsatz von JPA 2.x in Java-EE-Anwendungen
 
Einführung in nosql // ArangoDB mit Symfony 2
Einführung in nosql // ArangoDB mit Symfony 2Einführung in nosql // ArangoDB mit Symfony 2
Einführung in nosql // ArangoDB mit Symfony 2
 
Reactive Programming
Reactive ProgrammingReactive Programming
Reactive Programming
 
Doctrine 2 - An Introduction (German)
Doctrine 2 - An Introduction (German)Doctrine 2 - An Introduction (German)
Doctrine 2 - An Introduction (German)
 
Einstieg In Oop
Einstieg In OopEinstieg In Oop
Einstieg In Oop
 
Speeding up Java Persistence
Speeding up Java PersistenceSpeeding up Java Persistence
Speeding up Java Persistence
 
Backbase Intro
Backbase IntroBackbase Intro
Backbase Intro
 
Migration auf die OBIEE - OPITZ CONSULTING - Till Sander
Migration auf die OBIEE - OPITZ CONSULTING - Till SanderMigration auf die OBIEE - OPITZ CONSULTING - Till Sander
Migration auf die OBIEE - OPITZ CONSULTING - Till Sander
 
The Lotus Code Cookbook
The Lotus Code CookbookThe Lotus Code Cookbook
The Lotus Code Cookbook
 
Feige sein! Testen im Java-EE-Umfeld
Feige sein! Testen im Java-EE-UmfeldFeige sein! Testen im Java-EE-Umfeld
Feige sein! Testen im Java-EE-Umfeld
 
Legacy Code refaktorisieren
Legacy Code refaktorisierenLegacy Code refaktorisieren
Legacy Code refaktorisieren
 

More from Oliver Belikan

Neues von XSLT 2.0 und XPath 2.0
Neues von XSLT 2.0 und XPath 2.0Neues von XSLT 2.0 und XPath 2.0
Neues von XSLT 2.0 und XPath 2.0Oliver Belikan
 
Frontendtechnologien Fuer Ria V1.0
Frontendtechnologien Fuer Ria V1.0Frontendtechnologien Fuer Ria V1.0
Frontendtechnologien Fuer Ria V1.0Oliver Belikan
 
Technologievergleich für RIA
Technologievergleich für RIATechnologievergleich für RIA
Technologievergleich für RIAOliver Belikan
 
Rich Internet Applications
Rich Internet ApplicationsRich Internet Applications
Rich Internet ApplicationsOliver Belikan
 
Warum es sich lohnt mit Identity Management zu beschäftigen
Warum es sich lohnt mit Identity Management zu beschäftigenWarum es sich lohnt mit Identity Management zu beschäftigen
Warum es sich lohnt mit Identity Management zu beschäftigenOliver Belikan
 
Produkt Produkt Manager
Produkt Produkt ManagerProdukt Produkt Manager
Produkt Produkt ManagerOliver Belikan
 

More from Oliver Belikan (6)

Neues von XSLT 2.0 und XPath 2.0
Neues von XSLT 2.0 und XPath 2.0Neues von XSLT 2.0 und XPath 2.0
Neues von XSLT 2.0 und XPath 2.0
 
Frontendtechnologien Fuer Ria V1.0
Frontendtechnologien Fuer Ria V1.0Frontendtechnologien Fuer Ria V1.0
Frontendtechnologien Fuer Ria V1.0
 
Technologievergleich für RIA
Technologievergleich für RIATechnologievergleich für RIA
Technologievergleich für RIA
 
Rich Internet Applications
Rich Internet ApplicationsRich Internet Applications
Rich Internet Applications
 
Warum es sich lohnt mit Identity Management zu beschäftigen
Warum es sich lohnt mit Identity Management zu beschäftigenWarum es sich lohnt mit Identity Management zu beschäftigen
Warum es sich lohnt mit Identity Management zu beschäftigen
 
Produkt Produkt Manager
Produkt Produkt ManagerProdukt Produkt Manager
Produkt Produkt Manager
 

Workshop zu Hibernate 3.2.2 GA

  • 1. doubleSlash Net-Business GmbH Rainer Müller Fon 07541/6047-100 Müllerstr. 12 B D-88045 Friedrichshafen http://doubleSlash.de » Java-Persistenz mit Hibernate « Technology Days 2007 - Workshop
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. » Ein einfaches Beispiel – Hibernate Konfigurationsdatei « <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <!DOCTYPE hibernate-configuration PUBLIC &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name=&quot;hibernate.connection.driver_class&quot;>com.mysql.jdbc.Driver</property> <property name=&quot;hibernate.connection.url&quot;>jdbc:mysql://horizon:3306/demodb</property> <property name=&quot;hibernate.connection.username&quot;>user</property> <property name=&quot;hibernate.connection.password&quot;>geheim</property> <!-- SQL dialect --> <property name=&quot;hibernate.dialect&quot;>org.hibernate.dialect.MySQLInnoDBDialect</property> <!-- JDBC connection pool (built-in) --> <!--property name=&quot;connection.pool_size&quot;>10</property--> <!-- Disable the second-level cache --> <property name=&quot;cache.provider_class&quot;>org.hibernate.cache.NoCacheProvider</property> <!-- Enable Hibernate's automatic session context management --> <property name=&quot;current_session_context_class&quot;>thread</property> <!-- Mapping files --> <mapping resource=&quot;Person.hbm.xml&quot;/> <mapping resource=&quot;Address.hbm.xml&quot;/> </session-factory> </hibernate-configuration>
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. » Fallstrick Lazy-Initialisierung (2) « SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; PersonDAO dao = DAOFactory.getPersonDAO(); Person person = null; Address address = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); person = dao.getPerson(4711); Hibernate.initialize(person.getAddress()); tx.commit(); } catch (Exception e) { rollback(tx); } person.getAddress(); // <- keine Exception address.getStreet(); // <- keine Exception Lösungsmöglichkeit 1 : Lösungsmöglichkeit 2 : SessionFactory sf = HibUtil.getSessionFactory(); Session session = null; Transaction tx = null; PersonDAO dao = DAOFactory.getPersonDAO(); Person person = null; Address address = null; try { session = sf.getCurrentSession(); tx = session.beginTransaction(); person = dao.getPerson(4711); address = person.getAddress(); // <- keine // Exception tx.commit(); } catch (Exception e) { rollback(tx); } address.getStreet(); // <- keine Exception
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. Ihr IT-Partner für individuelle Softwarelösungen doubleSlash Net-Business GmbH Müllerstr. 12 B / D-88045 Friedrichshafen http://doubleSlash.de / info@doubleSlash.de Herzlichen Dank für Ihr Interesse.