Archive for February, 2009

h1

Two draws in quick succession

February 23, 2009

Considering that my past two games (both with black) were played over a month ago and I haven’t had time to annotate them in detail, I figured I would post them up together, with fewer notes than normal. While they both ended as draws, I was clearly winning in both cases, only to throw it away each time. Ok, enough whining. Here’s the first game:

1. e4 c5 2. Nc3 e6 3. g3 d5 4. d3 Nc6 5.  Bg2 Nf6 6. f4

Here I decided to trade in the center.

6…dxe4 7. Nxe4 Nxe4 8. Bxe4 Qb6 9. c3 Bd7 10. Qc2 Bd6 11. Be3 Qc7  12. Ne2 Ne7 13. d4

Here, the computer suggests 13…c4 with an advantage for black. I probably should have considered that option more seriously but more tempting was my own choice in the game – sacrificing a pawn for a nice open game with the initiative.

13…Bc6 14. dxc5 Bxc5 15. Bxc5 Bxe4 16. Qxe4 Qxc5 17. Qxb7 O-O

After a pretty forced sequence, Fritz gives a marginal advantage for white, primarily because of the extra pawn.

18. b4 Rab8?!

Provoking my opponent into making a choice. He chooses the trade of his queen for both of my rooks. Materially he is doing much better but I still have chances before his pieces coordinate.

19. Qxb8 Qd5 20. Qxf8+?!

20. Qxa7 Qxh1+ 21. Qg1 maintains the advantage.

20…Kxf8 21. Kf2 Nf5 22. Rhd1 Qe4 23. Rac1?

Too passive. 23. Rd8+ Ke7 24. Rad1, doubling the rooks on the d file and white should be ok.

23…Qe3+  24. Ke1 Qf3 25. c4 Qh1+ 26. Kd2 Qxh2 27. Rc3 Nd4 28. Re1 Qf2 29. Kd1 Nf3 30.  Rxf3 Qxf3 31. Kd2 Qa3 32. b5 Qxa2+ 33. Kd3 Qa3+ 34. Nc3 Qd6+ 35. Kc2 Qd4 36.  Kb3 Qf2 37. Rd1 Qxg3 38. c5 Qxf4 39. c6 Ke8 40. Rd7 Qf2 41. Rb7 Kd8 42. Rd7+  Kc8 43. Re7 h5 44. Rb7 h4 45. b6

Until now, I’ve slowly built up the advantage and am now clearly winning.

45…a6??

“Trying to be safe”. I saw the variation 45…Qxb6 46. Rxb6 axb6 with 4 connected passers against a lonesome knight. I was dreading that this flashy approach might have a blunder somewhere and didn’t go for it – rather than trusting my instincts. Even safer would have been to play 45…axb6 46. Na4 Qf3+ followed by Qxc6. Again, game over.

Instead, we shortly agreed on a draw!

46. Rc7+ Kd8 47. Rd7+ Ke8 48. Rb7 Kd8 49.  Rd7+ 1/2-1/2

And the next game, played a week after the previous one:

1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6  5. Nc3 a6 6. f4 Nc6 7. Be2 Qb6 8. Nxc6 bxc6 9. Qd3 g6 10. Rb1 Bg7 11. Be3 Qc7  12. O-O O-O 13. f5 Rb8 14. Kh1 Nd7 15. Bg5 Ne5 16. Qe3 Re8 17. f6 exf6 18. Bxf6  Bf8 19. Qg5 Be7 20. Rf4 Bxf6 21. Rxf6 d5 22. exd5 cxd5 23. Rbf1 Be6 24. R1f4??

Nothing spectacular until white’s last move, which is a clear blunder. He’s hoping he has enough on the kingside for a winning attack but I’ve concretely calculated he doesn’t and proceed to collect material and a winning advantage.

24…Rxb2 25. Rh4 Qxc3 26. Qh6 Rb1+ 27. Bf1 Qe1 28. Qxh7+ Kf8 29. Rhf4 Rb4 30. h4  Rxf4 31. Rxf4 Qg3??

And now my turn for the double question-mark! I was intending to play Ng4 first and after calculating several variations in my head, I simply played the wrong move order. Now my opponent wins back the piece and I lose the win.

32. Qh8+ Ke7 33. Qxe5 Qa3 34. Qc7+ Kf8 35. Bd3 Qc1+ 36. Rf1  Qh6 37. g3 g5 38. Kg2 gxh4 39. gxh4 Qxh4 40. Rh1 Qg4+ 41. Kf2 Qd4+ 42. Kg2

Here I knew I had a slight plus and could probably push on for a while, though I’d have to be extremely wary on an open board. But I took a look around at the other boards – three games had already completed with our team up 2-1, and my teammate on board one looked like he was closing in on another win. I felt that my half point made a lot more sense and chose to repeat.

42…Qg4+  1/2-1/2

h1

To ORM or not to ORM, that is the question

February 12, 2009

What is the best way to access a relational database from an object-oriented application?

I understand OOP. I understand relational databases. Assuming the database is wafer-thin (just tables) and that all of the logic lives within the application, there are various ways to get the two working together. In Java-land, JDBC provides a mechanism to write real SQL in your Java application. For each such query, you (as the developer) are responsible for providing the mapping. Spring’s JDBC templating provides a slightly easier way to implement the same functionality. ORM frameworks have also been around for a while. My initial impressions after using JPA/Hibernate for the past few months:

Benefits

  • You specify an annotated domain object and JPA magically does (reverse-)mapping between the object and the database table.
  • You are abstracted away from the different flavours of SQL that different databases use.
  • CRUD operations abstract relational concepts from OOP land.

Drawbacks

  • Defining complex relational queries in OO ain’t easy. It’s certainly hard to define and is most likely not the most efficient. I have never worked with OO databases but if I am going to specify all (or most) of my database access with object oriented constructs, why not just try an object oriented database instead? I realise they don’t have the same reputation as relational ones, but why not, in this case?
  • I don’t know if others have the same problem, but I seem to have a REAL problem understanding a database transaction (the @Transaction annotation in JPA land) in the context of object oriented code. Especially since I don’t understand how much Hibernate caches and when it actually flushes and synchronises with the database.

Reading documentation hasn’t really helped either – I probably need to create tests with several different scenarios to see what really happens underneath. And until I do that, I will hesitatingly continue to use JPA, while nostalgically remembering the explicit control of JDBC and raw SQL.