Posts Tagged JPA

Hibernate Smoke Detector

Tags: , , ,

There is a time in the life of every project when Database Administrator starts to look suspiciously at queries generated by our application. And then he (or she) sends us long list of queries that are not optimized, do not have proper indexes set or are executed multiple times in a very short time. And of course our role is to fix it.

Some issues are hard to solve but most of them are effect of our mistakes: N+1 problem in Hibernate is well-known (e.g. StackOverflow discussion) or checking the same condition (e.g. count something to figure visibility) multiple times for many components on the same page without caching it it any way. Of course we could turn on sql/hql logging during development process but sometimes we might not notice that here or there there is a problem with some query.

Solution

And here comes the solution. Simple parser analyzing hql logs and reporting which queries are executed too often. It’s far from being perfect or super universal but it works I called it Hibernate Smoke Detector.

Continue reading this post …


Be Sociable, Share!

Wicket Tutorial, part 1 – setting up project with Spring 3, JPA 2 and MySQL

Tags: , , , , , ,

Today I start my personal project Item Directory which will be developed as a element of Wicket Tutorial series on this blog. Item Directory will be a web application to help you manage your collections of items (books, CDs, movies or even postage stamps). Application is built with Java, Wicket, JPA, Spring 3 and MySQL as a database. It is a response for my family needs to manage some items hidden in shelves, bookcases and cabinets where we need something and we think “We have it somewhere, but I have no idea where it is located” :)

Is this Wicket tutorial for me?

This tutorial is for Java developers who want learn about this great framework in practise not only from reading a book. Because I like to learn while creating something, this tutorial will guide you through development process. I will concentrate mainly on adding new features and developing project instead of explaining every single aspect of how Wicket works in its internals or every single line of code I created. But those parts I think are worth some explanation will be discussed in detail.

Of course if something seems unclear to you or you think I should write some longer explanation in some part of my post, please send a comment and I will try to answer to your needs as best as I can :) Moreover all code will be available to download from Mercurial repository, so you can easily download and deploy application with Jetty to test and see how it exactly works.

And last thing: as it is my first bigger tutorial published here, all comments, suggestions, etc. are very appreciated. Additionally, ideas what to do/implement next are also welcome and will be considered :)

Continue reading this post …


Be Sociable, Share!

Java Persistence API and simple audit

Tags: , , , , ,

Recently for a first time  have to create in the application functionality to track changes in the database made by users. There are some existing solutions and one of I found using Google is very interesting article at JavaLobby “Using a Hibernate Interceptor to set audit trail properties”. But there is a much simpler solution which I present here.

If we are using Java Persistence API we can pick very useful annotations: @PrePersist and @PreUpdate. Suppose that in every class we want to gather data about who and when created database record and who and when edited it for a last time. Because such functionality is needed in every entity class we can move logic to common abstract class which will be extended by all concrete entity classes: Continue reading this post …


Be Sociable, Share!