Problem:
- Product Name: Borland Enterprise Server (Application Server)
- Product Version: 6.6
- Product Component: Hibernate web example
- Platform/OS Version: All
How to migrate from hibernate version 2.1 to hibernate 3.2 in "order_hibernate" example?
Resolution:
BAS6.6 hibernate example "/examples/web/order_hibernate" uses hibernate version 2.1, since current version of hibernate is 3.2, the following white-paper provides tips for migration:
Here is a "order_hibernate example" specific migration tips,
1) Replace libraries at examples/web/order_hibernate/lib
cglib-2.0-rc2.jar
commons-collections-2.1.jar
commons-logging-1.0.3.jar
ehcache-0.6.jar
hibernate2.jar
odmg-3.0.jar
with the downloaded hibernate3.2 libraries:
antr-2.7.6.jar
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ehcache-1.2.jar
hibernate3.jar
JSTLs are no need to replace:
jstl.jar, standard.jar
2) Rewrite codes. The number(s) appended to filename indicates the index of code change.
examples/web/order_hibernate/src:
hibernate.cfg.xml(1,2,4)
examples/web/order_hibernate/src/com/borland/examples/web/orderh:
DataAccessManager.java(1,5)
HibernateUtil.java(1)
LineItem.hbm.xml(2,3)
Order.hbm.xml(2,3)
PopulateManual.java(1)
Change index:
- The Hibernate3 package structure is rooted at org.hibernate instead of net.sf.hibernate. So need to change all "net.sf" to "org".
- Change http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd to http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in the DOCTYPE.
- Since it is best practice to map almost all classes and collections using lazy="true", that is now the default. Existing applications will need to explicitly specify lazy="false" on all non-lazy class and collection mappings.
- "org.hibernate.dialect.JDataStoreDialect" has been added.
- Replaced a line
session.delete("from Order");
with
session.createQuery("DELETE from LineItem").executeUpdate();
session.createQuery("DELETE from Order").executeUpdate();
Hibernate3 applications should use createQuery() for all query execution, DELETE queries for bulk delete and merge() instead of saveOrUpdateCopy().
#VisiBroker
#Security