On Thu, Nov 14, 2002 at 01:36:13PM -0600, Urberg, John wrote:
.
> The InvoiceRepository would be implemented like this:
>
> public class HibernateInvoiceRepository {
> public void setDatabase(Database database) { _database =
> (HibernateDatabase) database; }
> public List getOverdueInvoices() {
> return database.getSession().find("<hibernate query>");
> }
> public void update(Object object) {
> database.getSession().saveOrUpdate(object);
> }
> }
>
And where do you close those opened sessions using this design? Also, where
did you find a place to implement transaction handling, including joining
into existing transactions if possible?
I have my own pieces of ideas how to implement a design for Hibernate, but
I'm fighting with the questions listed above too. Got some workaround, but
kinda far from being perfect.. Mainly I used Ralf's third possible solution
from these:
> > * Put everything into the domain classes.
> > * Implement something like a "Home" interface
> > * Implement some sort of component-like / "Service" interface
.having a layer of 'service-like' components in charge of database-related
operations, which either use Hibernate (98%) or plain JDBC pulling the
connection from a Hibernate session. These components are always pulled by
the upper layer from a plain component pool, which I implemented myself. But
mentioning one returning problem, I have *LOTS* of repeated code parts like
these:
Session session = null;
Transaction tx = null;
try {
session = Hibernator.getSession(); // my custom class which keeps
the sessions and initializes Hibernate
tx = session.beginTransaction();
..
..
tx.commit();
} catch (Exception e) {
logger.error (<blah/>), e);
tx.rollback();
// rethrow business-exception if suitable
} finally {
if (session != null) session.close();
}
These piece of codes are repeating in almost ALL of the Service classes'
business methods, are just flooding all the logic badly :( (ok, tx handling
is missing from this where i'm doing read-only operations, but still..) I
also have some part-solution related to joining to existing transactions,
but I find it snappy too.
So, as I said, I don't feel my design good at all.. just couldn't find out
any better for the moment. Therefore, I'd be very happy and thankful to read
about others experiences and concrete architecture/design plans.
Regards,
dyn
--
.Digital.Yearning.for.Networked.Assassination.and.Xenocide
-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing
your web site with SSL, click here to get a FREE TRIAL of a Thawte
Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel