When I finished the blog features on this site, the next big thing on my list was developing a way to index and search the contents. I didn't want to let Google do it for me, because that's like cheating. I had heard good things about Lucene (actually great things, I know a guy who uses it for everything from searching for products in a web store to indexing biological information), so I started looking into that.
I was happy when I discovered Hibernate Search, a library that simplifies mapping a Hibernate domain model to Lucene's searching capabilities. I was even happier when I discovered that Hibernate Search has excellent support for JPA, which is the API I used for this site. In the rest of this post I'll outline the steps I had to take to add Hibernate Search to this site. It ended up being much easier and more intuitive than I had expected...
I found this months ago on YouTube, and I still find myself watching it at least once a week. The song itself (Rachmaninoff Prelude Op. 23 No. 5) is fantastic, but Gilels' performance is simply perfect, with expression that blows away all the other ones I've heard. I had to go out and buy the music, but it's crazy hard – I still haven't gotten the first 30 seconds down yet.
Maybe it would help if I grew an awesome combover-style hairdo like his.
I've been working on an update to this site that adds blogging & commenting features. It's a Spring + JPA site, so I created a Post object and a PostDAO and built all the new features using those classes. Everything worked perfectly until I implemented the delete controller. When trying to delete a Post, I was getting the following exception:
org.springframework.dao.InvalidDataAccessApiUsageException: Removing a detached instance com.musicstore.model.Post
I debugged the exception, searched all over the place and couldn't figure what was causing the exception, which was occurring within a getJpaTemplate().remove(post) call. After an hour or two of fruitless googling, I decided to read up on JpaSupport (which the PostDAO extends) and look more closely at my code. I finally realized what the problem was when I noticed that JpaSupport provides callbacks when you need to access an EntityManager directly – but I wasn't using them...
Newer posts » |