Navigation

RSS 2.0 New Entries Syndication Feed Atom 0.3 New Entries Syndication Feed

Show blog menu v

 

General

Use it

Documentation

Support

Sibling projects

RIFE powered

Valid XHTML 1.0 Transitional

Valid CSS!

Blogs : Latest entries

< Previous page 
How do you use Hibernate Extended Sessions?

The Open Session in View pattern is very popular when Hibernate is used in a web application. This allows you to safely use managed entities when your view is being rendered. At Terracotta, we're currently researching what other patterns are popular for Hibernate and how people apply them.

One that I'm in particular looking into is the Extended Session pattern for long running conversations. This allows you to disconnect a Hibernate session in between requests and to store it in the HTTP session in the meantime.

I'd like to know who's using the extended session pattern and what you use it for.

To understand more about this, I developed a small example application to get a feel for the advantages, the benefits, the gotchas and the surprises. The application can be found below, it is inspired by snippets from Hibernate tutorials and example applications:

http://svn.terracotta.org/svn/forge/projects/hibernate-disconnected/trunk/

The example uses only servlets, filters and Hibernate. It is a webapp that allows you to create events and add people to it over different requests. When an event has been created with all the relevant people, it can be committed in one step. The intermediate state is kept within the managed entities and the Hibernate session until it's flushed.

This is what I found worth mentioning:

  • Whenever a transaction is created and committed, it doesn't matter if Hibernate flush mode is set to manual, certain operations like persist and merge will be propagated to the database at transaction commit. However, modifications to managed entities wont be committed, this can be confusing.
  • Even with manually flushed sessions, transactions are always real database transactions, causing locks to be held. They thus need to be as short as possible.
  • A single general-purpose servlet filter might not be feasible, depending on how transactions should behave. In this application, I ended up creating only a transaction around the actual session flush.
  • Data that is present in a manually flushed session buffer is batched but not available for queries.
  • This doesn't behave the same as a database transaction with isolation levels that can still see their own changes.
  • If the data needs to be available for a query, a commit needs to happen first.
  • This can require application changes, like a redirect after form submission in case transactions are automatically committed through a servlet filter.

Totally unrelated but cool, you can use an AnnotationConfiguration class to setup the Hibernate config and use a fluent interface to add the managed entity classes. This reduces the amount of XML and eases maintenance (see HibernateUtil class in my example).

posted by Geert Bevin in Java on Apr 16, 2009 3:53 PM : 4 comments [permalink]
 
JavaZone 2008 : Bytecode Manipulation in the Real World

I just finished my talk at JavaZone 2008 about bytecode manipulation.

You can download the presentation's PDF file from:

http://uwyn.com/download/bytecode_real_world.pdf

This is the abstract:

Bytecode Manipulation in the Real World

Bytecode manipulation has become increasingly popular over the last years. It is used by JPA implementations, application servers, AOP libraries, web frameworks, monitoring systems, profilers, clustering solutions, scripting languages, workflow engines, and much more. In fact, most of today's applications will most probably rely on byte code manipulation, often even without realizing.

Application developers however seem to be overly careful and often frown upon bytecode manipulation as an arcane art that is risky and difficult to understand. This presentation will show you that it's easier than you think. We'll go over concise examples that illustrate the concepts. Distinct patterns, coming from different domains, will give you ideas about adopting byte code manipulation for your own products. You'll learn arguments to reassure skeptics and see how the manipulation can plugged into your tool chain. We'll finish off with tips and tricks to write maintainable code with the ASM library.

After this session you'll see byte code manipulation as another tool in your arsenal and you'll have a good picture of how to start using it yourself.

Outline:

  • What is bytecode manipulation?
  • Some popular projects that use it
  • Don't be afraid
  • Plug in the manipulation
  • Best practices
posted by Geert Bevin in Java on Sep 17, 2008 1:29 PM : 0 comments [permalink]
 
Speaking at TSSJS 2008 Europe in Prague

Next month I'll be speaking at TheServerSide.com Java Symposium.

The topics I will cover are:

I've done both sessions before and they're pretty solid now.

The 'Boldly go...' one has been a huge success at JavaOne as it was booked completely full and I did a repeat session on Friday that still had quite good attendance.

See you in Prague!

speaking at TSSJS 2008

posted by Geert Bevin in Java on May 21, 2008 12:41 PM : 0 comments [permalink]
 
Closing several JDBC statements cleanly

It's been a while since I wrote some raw JDBC code. I didn't remember that it was so tedious to manually close a series of PreparedStatement objects and make sure that any exception was properly handled and reported.

Note that the ARM blocks or BGGA closures proposals don't make this easier since this cleanup should be done after the prepared statements have been used for a while in various other methods, it doesn't automatically have to be done at the end of a lexical scope.

This is what I came up with.

Of course, you could write an alternative implementation that creates some kind of repository for the prepared statements in a map and then provide a method that closes them all by going over the entries of the map while preserving the exceptions in a similar manner. Any other suggestions or comments for this to be done better?

private PreparedStatement psStmt1;
private PreparedStatement psStmt2;
private PreparedStatement psStmt3;
 
public void cleanup() throws SQLException {
  SQLException exception = null;
  if (psStmt1 != null) {
    try {
      psStmt1.close();
    } catch (SQLException e) {
      exception = e;
    } finally {
      psStmt1 = null;
    }
  }
 
  if (psStmt2 != null) {
    try {
      psStmt2.close();
    } catch (SQLException e) {
      if (exception != null) e.setNextException(exception);
      exception = e;
    } finally {
      psStmt2 = null;
    }
  }
 
  if (psStmt3 != null) {
    try {
      psStmt3.close();
    } catch (SQLException e) {
      if (exception != null) e.setNextException(exception);
      exception = e;
    } finally {
      psStmt3 = null;
    }
  }
 
  if (exception != null) {
    throw exception;
  }
}
posted by Geert Bevin in Java on Jan 30, 2008 6:11 PM : 4 comments [permalink]
 
Java Champions interviews at JavaPolis 2007

At JavaPolis 2007, Aaron Houston the coordinator of the Sun Java Champions program, recorded a whole collection of short interviews with the Java Champions that were present at the conference (2-8 mins).

If you're wondering what the Java Champions are up to, or even who or what they are, this is a easy and quick way to find out.

The interviews can be found on the Java Champions homepage and will eventually move to the library section.

You can listen to my interview directly here (6 min 12 MB):

https://java-champions.dev.java.net/mp3/JP07-geert-bevin.mp3

posted by Geert Bevin in Java on Jan 4, 2008 7:20 PM : 0 comments [permalink]
 

< Previous page 
 
 
 
Google
rifers.org web