[Dev] New support for Hibernate XML mapping files

Edmund Grossenbacher egrossenbacher at alterpoint.com
Wed May 7 13:15:29 CDT 2008


I didn't realize you guys were already using NamedQueries.  They have a few drawbacks, but hey, none of these are killers:

1) annotations bury queries in Java code

2) SQL queries are harder to tailor to specific database syntax, which could be supportable with the XML approach by URL munging when the AnnotationConfiguration is built (albeit this would require more work than I have done to date)

3) queries that span multiple entities, return multiple entities, etc., end up apparently associated with an arbitrarily chosen Java class,

4) long query strings end up being split across multiple lines using string concatenation, resulting in harder to read, harder to edit queries.

But YMMV.  In any case, I *believe*, but have not verified, that if we switch to the EntityManager and it's associated createNamedQuery(...) methods we will still pick up these XML based queries.  I'm not 100% positive here, because the EJB-3 persistence spec defines its own XML configuration capability, including named query support.  I'm not sure how all of that works.

However, from my perspective, there is nothing to gain from the pure JPA approach except a bunch of refactoring.  So if possible, it would be *awesome* if you could maintain backwards compatibility with the zap.hibernate stuff, because currently I'm using Hiberate specific objects everywhere (the SessionFactory, Session, and Query objects that get scattered throughout code are all from the org.hibernate namespace.)

-ed

=====

Cool extension, and I don't mind the addition, but ZipTie developers take note that I prefer named query annotations on the class. They do the same thing and are associated with the object/table on which they operate. We don't have any pure DBA/SQL folks who eschew Java. :-)

@NamedQuery(

name="getAllOrder",

queryString="SELECT OBJECT(o) FROM CustomerOrder as o WHERE

o.customerId = :customerId")

And subsequently:

Query allOrders = em.createNamedQuery("getAllOrder");

allOrders.setParameter("customerId",customerId);

Collection <CustomerOrder> results = allOrders.getResultList(); return results;

Ed, I was planning to switch our org.ziptie.zap.hibernate to a pure JPA approach in the next two releases? Are these named queries in XML resource files Hibernate specific? If so, when I do the refactor, I'll be sure to encapsulate it in a new bundle (org.ziptie.zap.jpa) so that there is a graceful fork/non-conflicting branch.

-Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ziptie.org/pipermail/dev/attachments/20080507/8821bd24/attachment.html 


More information about the Dev mailing list