• Home
  • RSS Feed
  • Register
  • Log in

Archive for the ‘Spring’ Category

Older Entries

@Composite - Macro Annotations for Java
Posted by Andrew Phillips in the early morning: June 23rd, 2009

Some months ago I attended a presentation at which Wilfred Springer demonstrated his very cool Preon binary codec library. Defining binary file formats in Preon requires quite a lot of fairly repetitive sets of annotations, and during a chat after the talk Wilfred mentioned (in fact, he blogged about it) how much more convenient it would be if one could just define "shortcuts":

@RequiredEnumProperty(column = "AGENT")

for

@NotNull
@Column(name = "AGENT")
@Enumerated(EnumType.STRING)
 

for instance - and use those instead. Sort-of "macro annotatations" for Java, if you like.
A thought that has presumably also occurred to many frequent users of Hibernate, JAXB or other annotation-heavy frameworks.

Well, it took me rather longer than the couple of days it would probably have taken a developer of Wilfred's skill, but finally @Composite is here! (more...)

  • Bookmark

Tags: annotation, composite, Java, macro
Filed under Java, Spring | 4 Comments »

JPA implementation patterns: Service Facades and Data Transfers Objects
Posted by Vincent Partington at around evening time: May 11th, 2009

In my previous blog on JPA implementation patterns, I touched upon the subject of the DTO and Service Facade patterns. In this blog I will explore why we would even need such patterns and put these patterns and the DAO pattern into the broader context of JPA application architecture.

If there is one thing that I learned when implementing JPA for the first time is that some of the "old school" enterprise application architecture patterns still apply, even though some people have proclaimed them to be no longer necessary:

  • The DAO has been declared dead because you might just as well invoke the EntityManager directly. It provides a nice enough interface and switching from JPA to a different persistence implementation is not something the DAO abstraction would make much easier.
  • DTO's have been deemed superfluous because you can also use your domain objects directly in the presentation layer. This is made possible by a combination of the open EntityManager in view pattern, tag libraries to display your domain objects in JSP's and data-binding utilities to map HTTP request parameters back to domain objects.
  • And finally Service Facades also seem to have gone out of fashion. Instead you can have the controller directly invoke the services it needs or, even simpler, directly contain the business logic.

(more...)

  • Bookmark

Filed under JPA, JPA implementation patterns, Java, Spring | 6 Comments »

JPA implementation patterns: Lazy loading
Posted by Vincent Partington at around evening time: April 27th, 2009

In the previous three blogs about JPA implementation patterns, I covered the basis operations of saving entities, retrieving entities, and removing entities. In this blog I will continue along a different angle, exploring the subject of how entities are lazily loaded and how that affects your application.

Anybody that has been working with Hibernate for a while has probably seen a LazyInitializationException or two, usually followed by a message such as "failed to lazily initialize a collection of role: com.xebia.jpaip.order.Order.orderLines, no session or session was closed" or "could not initialize proxy - no Session". Even though these message may baffle new users of Hibernate, they are a lot better than the NullPointerExceptions OpenJPA gives you in these cases (at least when using runtime bytecode enhancement).

To use JPA to its full potential it is imperative to understand how lazy loading works, as it allows you to model your complete database with all its relations without loading that whole database as soon as you access just one entity.
(more...)

  • Bookmark

Filed under Hibernate, JPA, JPA implementation patterns, Java, Spring | 5 Comments »

JPA implementation patterns: Data Access Objects
Posted by Vincent Partington mid-afternoon: March 9th, 2009

The JPA, short for Java Persistence API, is part of the Java EE 5 specification and has been implemented by Hibernate, TopLink, EclipseLink, OpenJPA, and a number of other object-relational mapping (ORM) frameworks. Because JPA was originally designed as part of the EJB 3.0 specification, you can use it within an EJB 3.0 application. But it works equally well outside of EJB 3.0, for example in a Spring application. And when even Gavin King, the designer of Hibernate, recommends using JPA in the second edition of Hibernate in Action, a.k.a. Java Persistence with Hibernate, it's obvious that JPA is here to stay.

Once you get over your fear of annotations ;-), you find that there is plenty of literature out there that explains the objects and methods within the API, the way these objects work together and how you can expect them to be implemented. And when you stick to hello-world-style programs, it all seems pretty straight forward. But when you start writing your first real application, you find that things are not so simple. The abstraction provided by JPA is pretty leaky and has ramifications for larger parts of your application than just your Data Access Objects (DAO's) and your domain objects. You need to make decisions on how to handle transactions, lazy loading, detached object (think web frameworks), inheritance, and more. And it turns out that the books and the articles don't really help you here.
(more...)

  • Bookmark

Filed under Hibernate, JPA, JPA implementation patterns, Java, Spring | 28 Comments »

Maybe annotations aren’t that bad after all
Posted by Vincent Partington at around evening time: January 19th, 2009

Two years ago I blogged about annotations and that I considered them to be A Bad Thing. It seems I will have to eat my words. I am actually using them to the hilt in my current project.

We use JPA and specific Hibernate annotations on our entities. See for example these annotations on a field:
@OneToMany(mappedBy = "changePlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@org.hibernate.annotations.Sort(type = org.hibernate.annotations.SortType.COMPARATOR,
    comparator = PositionableComparator.class)
private SortedSet steps = new TreeSet(new PositionableComparator());

(more...)

  • Bookmark

Filed under Hibernate, Java, Spring | 4 Comments »

Spring 2.x schema based configuration and the PropertyPlaceholderConfigurer
Posted by Vincent Partington in the early evening: January 1st, 2009

Spring 2.0 and later versions offer schema based configuration that allows us to have a more expressive and concise way to specify our configuration. For example, Spring Security 1.0 configuration used to be quite hairy, but became a lot simpler with Spring 2.0.

One disadvantage is that the documentation of the namespaces is not as good as that for regular beans. For regular beans, I can have a look at Javadoc, while for the namespaces that come with Spring the documentation is not up to the same level of detail. Until a Javadoc-like tool can generate this documentation from the schemas, the best documentation is the schemas themselves.

One little problem

But ignoring that issue, I recently ran into a very practical problem with using schema based configuration in combination with a PropertyPlaceholderConfigurer.
(more...)

  • Bookmark

Filed under Java, Spring | No Comments »

Configuring Hibernate and Spring for JTA
Posted by Maarten Winkels mid-afternoon: July 18th, 2008

Spring is a great framework for dependency injection and it comes with a lot of support classes and utilities for all kind of things. Hibernate is a persistence service with a lot of useful features, that is relatively easy to use. Configuring both frameworks is not always easy. Configuring them together is sometimes hard and it is easy to make mistakes.

This blog addresses a problem in a configuration that is fairly common: use Spring for transaction management on top of a JTA provider and use Hibernate for persistence. Transaction demarcation is easy and declarative with Spring. The problem is that Hibernate sometimes needs to detect the current transaction and this needs to be configured. This leads to hard to detect bugs in applications that rely on auto flushing.
(more...)

  • Bookmark

Tags: auto flush, Hibernate, JTA, Spring
Filed under Hibernate, JTA, Spring | 2 Comments »

Testing Wicket with Fitnesse
Posted by Mischa Dasberg at around evening time: July 6th, 2008

On our latest project, My colleague Tjeerd Kaastra and I, have been using Wicket.
Since our GUI was so complex, and we had to write 100s of unit tests (a lot of corner cases), we sat down with our testers to find out how we should approach this. Because Our testers use Fitnesse to test both functional acceptance as well as regression tests, they test a lot of the code as well. So we thought, why not integrate the two and that is what we did.

This blog describes how to test Wicket applications using Fitnesse. It is about stretching the limits of the Wicket test components to do so. We will try to explain this by using a small example project we have created to illustrate things. This example project has been inspired on the new user wizard example by Eelco Hillenius. We adapted this example so that it uses Spring, because most apps use a backend system.

(more...)

  • Bookmark

Filed under Ajax, Java, Spring, Testing, Wicket | 7 Comments »

Flex Beyond — eForms
Posted by Balaji D Loganathan at around evening time: March 5th, 2008

Around 6 months back me and Vikas Hazrati gave a XTR on Adobe Flex to my colleagues in Xebia India.

We took some resources from Adobe Dev Net site and eventually found a cool article explaining how Flex Data Services works with Spring using Spring Remoting features and so on.
We were quite amazed with the UI capabilities of Flex with its server side integration. If you look at that article now, its start with a disclaimer saying "Effective with the release of Adobe LiveCycle ES, the Adobe Flex Data Services 2 server product has been rebranded as a Solution Component of LiveCycle ES."
(more...)

  • Bookmark

Filed under Architecture, Flex, Java, Requirements Management, Spring | No Comments »

Spring with Stripes - A Maven Based Sample Code
Posted by Balaji D Loganathan at around evening time: March 4th, 2008

The purpose of this post is to give a Maven based sample code of Spring with Stripes integration. The source code set is already in Eclipse project format, so you can use eclipse to view files content and structure.
This post will not explain about the techniques of integrating spring with stripes. The spring with stripes integration is very well explained at Stripes framework wiki page - Spring with Stripes. I kindly suggest you to read that documentation first before trying out the sample code given in this post. This post also assume that you are familiar with the basics of Maven, Eclipse, Stripes and Spring.

Few of the other "How to" samples (like Ajax addition, addition, echo, stripes layout reuse) that were documented in Stripes framework wiki page were also included in this sample code.
(more...)

  • Bookmark

Filed under Ajax, Eclipse, Flex, Java, Maven, Spring, Stripes | 1 Comment »

Older Entries


Archives

  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India

Categories

  • Java (233)
  • Agile (100)
  • General (50)
  • Performance (37)
  • Hibernate (35)
  • Podcast (31)
  • Testing (30)
  • Scrum (27)
  • Spring (24)
  • Project Management (22)
  • Architecture (22)
  • SOA (19)
  • Flex (17)
  • Maven (15)
  • Eclipse (14)
  • JPA (13)
  • Quality Assurance (12)
  • Groovy (12)
  • Articles (11)
  • Grails (11)

Tag Cloud

    plugin qcon offshoring fitnesse Ajax Scrum IntelliJ Semantic Web SOA Introduction to Agile Agile Poppendieck Testing Xebia Eclipse Hibernate OutOfMemoryError distributed Grails offshore Maven Lean Closures sutherland Agile Awareness Workshop Groovy Java Performance JavaOne Seam