LatJUG. JPA2 Done Right

750 views

Published on

Java User Group Latvia
February 2011
JPA2 Done Right
Denis Udod
http://goo.gl/rzD0q

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
750
On SlideShare
0
From Embeds
0
Number of Embeds
85
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

LatJUG. JPA2 Done Right

  1. 1. JPA2 Done Right
  2. 2. Easy JPA2 <ul><li>JPA2.0 + Hibernate3.6 + HSQLDB2.0 + Maven3 </li></ul>
  3. 3. Easy JPA2 <ul><li>JPA2.0 + Hibernate3.6 + HSQLDB2.0 + Maven3 </li></ul><ul><ul><li>Create project </li></ul></ul><ul><ul><ul><li>mvn archetype:generate … </li></ul></ul></ul>
  4. 4. Easy JPA2 <ul><li>JPA2.0 + Hibernate3.6 + HSQLDB2.0 + Maven3 </li></ul><ul><ul><li>Create project </li></ul></ul><ul><ul><ul><li>mvn archetype:generate … </li></ul></ul></ul><ul><ul><li>Edit pom.xml </li></ul></ul><ul><ul><ul><li>Add repository jboss </li></ul></ul></ul><ul><ul><ul><li>Add dependency </li></ul></ul></ul><ul><ul><ul><ul><li>hibernate-core </li></ul></ul></ul></ul><ul><ul><ul><ul><li>hibernate-entitymanager </li></ul></ul></ul></ul><ul><ul><ul><ul><li>hsqldb </li></ul></ul></ul></ul>
  5. 5. Easy JPA2 <ul><li>JPA2.0 + Hibernate3.6 + HSQLDB2.0 + Maven3 </li></ul><ul><ul><li>Ready to import into IDE  </li></ul></ul>
  6. 6. Easy JPA2 <ul><li>persistence.xml </li></ul><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd&quot; version=&quot;2.0&quot;> <persistence-unit name=&quot;org.hibernate.jpa&quot;> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>lv.jug.jpa.CustomerEntity</class> <properties> <property name=&quot;hibernate.connection.url&quot; value=&quot;jdbc:hsqldb:./.db/testfiles&quot;/> <property name=&quot;hibernate.connection.driver_class&quot; value=&quot;org.hsqldb.jdbc.JDBCDriver&quot;/> <property name=&quot;hibernate.connection.username&quot; value=&quot;SA&quot;/> <property name=&quot;hibernate.connection.password&quot; value=&quot;&quot;/> <property name=&quot;hibernate.archive.autodetection&quot; value=&quot;class&quot;/> <property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot;/> <property name=&quot;hibernate.format_sql&quot; value=&quot;true&quot;/> <property name=&quot;hbm2ddl.auto&quot; value=&quot;update&quot;/> </properties> </persistence-unit> </persistence>
  7. 7. Easy JPA2 <ul><li>persistence.xml </li></ul><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd&quot; version=&quot;2.0&quot;> <persistence-unit name=&quot;org.hibernate.jpa&quot;> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>lv.jug.jpa.CustomerEntity</class> <properties> <property name=&quot;hibernate.connection.url&quot; value=&quot;jdbc:hsqldb:./.db/testfiles&quot;/> <property name=&quot;hibernate.connection.driver_class&quot; value=&quot;org.hsqldb.jdbc.JDBCDriver&quot;/> <property name=&quot;hibernate.connection.username&quot; value=&quot;SA&quot;/> <property name=&quot;hibernate.connection.password&quot; value=&quot;&quot;/> <property name=&quot;hibernate.archive.autodetection&quot; value=&quot;class&quot;/> <property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot;/> <property name=&quot;hibernate.format_sql&quot; value=&quot;true&quot;/> <property name=&quot;hbm2ddl.auto&quot; value=&quot;update&quot;/> </properties> </persistence-unit> </persistence>
  8. 8. Easy JPA2 <ul><li>CustomerEntity </li></ul>
  9. 9. Easy JPA2 <ul><li>И вс e </li></ul>
  10. 10. Easy JPA2 ? <ul><li>И все же не все ? </li></ul>
  11. 11. Easy JPA2? <ul><li>Попробуем что нас получилось... </li></ul>
  12. 12. Easy JPA2 <ul><li>Идея: Для каждого Entity надо DAO  </li></ul>
  13. 13. Easy JPA2 ? <ul><li>Идея: Для каждого Entity надо DAO </li></ul>
  14. 14. Not Easy JPA2 ? <ul><li>Не хватит и 2-х экранов  </li></ul>
  15. 15. Not Easy JPA2 ? <ul><li>Опять много кода  </li></ul>
  16. 16. Done Right <ul><li>JPA2.0 + Hiernate3.6 + HSQLDB2.0 + Maven3 </li></ul><ul><ul><li>+ Hades http://redmine.synyx.org/projects/hades </li></ul></ul>
  17. 17. Done Right <ul><li>JPA2.0 + Hiernate3.6 + HSQLDB2.0 + Maven3 </li></ul><ul><ul><li>+ Hades http://redmine.synyx.org/projects/hades </li></ul></ul><ul><ul><li>Edit pom.xml </li></ul></ul><ul><ul><ul><li>Add dependency </li></ul></ul></ul><ul><ul><ul><ul><li>org.synyx.hades </li></ul></ul></ul></ul>
  18. 18. Done Right <ul><li>Создадим новое “hades-style” DAO </li></ul>
  19. 19. Easy JPA2 <ul><li>И вс e  </li></ul>
  20. 20. Easy JPA2 <ul><li>И вс e  </li></ul><ul><ul><li>не нужно больше плодить «одинаковый код» </li></ul></ul><ul><ul><li>Все DAO стало декларативным </li></ul></ul>
  21. 21. Easy JPA2 <ul><li>Hades http://hades.synys.org </li></ul><ul><li>Apache license 2.0 </li></ul>

×