Friday, December 26, 2008

Using JPA and Hibernate with Maven

I have been fighting a bit to set up a Maven project with JPA and Hibernate as persistence provider.

The final solution is very simple. But when you get on a wrong track at the beginning, you end up in a terrible maze...

So here the most important hint:
The JBoss repository (http://repository.jboss.org/maven2/) is quite a mess.
In the root of the repository you find directories (matching Maven GroupIds) for hibernate , hibernate-annotations and hibernate-entitymanager.
Do not use them!
They are outdated, do not provide current versions and most annoying do not declare their dependencies... so your pom will get a mess.

All dependencies should use the GroupId org.hibernate (browse into the org directory in the Maven repository).

So here is my working pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>domain</groupId>
  <artifactId>cascaded-locking</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>cascaded-locking</name>
  <url>http://maven.apache.org</url>
  <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
  </build>
    
  <dependencies>
	
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-entitymanager</artifactId>
		<version>3.4.0.GA</version>
	</dependency>
	
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.2</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

	<dependency>
		<groupId>org.apache.derby</groupId>
		<artifactId>derby</artifactId>
		<version>10.3.2.1</version>
		<scope>test</scope>
	</dependency>
	
  </dependencies>
  
  <repositories>
      <repository>
          <id>jboss</id>
          <url>http://repository.jboss.org/maven2</url>
      </repository>
  </repositories>

</project>


Thursday, December 25, 2008

Don't be too clever...

Brain-Power.jpg
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

--Brian Kernighan

Wednesday, December 24, 2008

Take it slow ...

snail.jpg
A unit test that takes 1/10th of a second to run is a slow unit test.

- Michael C. Feathers
Working effectively with legacy code

Thursday, December 18, 2008

If programming languages were ...

braindead-closeup.jpg After Web Framework Trolling and Language Wars now come the comparisons:

  • If programming languages were religions...
  • If programming languages were cars...


  • My favorites:
    APL would be Scientology - There are many people who claim to follow it, but you've always suspected that it's a huge and elaborate prank that got out of control.

    Eiffel is a car that includes a built-in driving instructor with a French accent. He will help you quickly identify and learn from your mistakes, but don't you dare argue with him or he'll insult you and throw you out of the car.

    Wednesday, December 17, 2008

    Go go java! ... play catch-up with C#!

    z1xgZtgVQr5h.jpg I am reading Stephen Colebourne's JDK 7 language changes - Devoxx votes!.

    At the devoxx conference people voted on possible future features of the Java language.

    As a developer with a .NET background, I can't help to compare with C# ...
  • Properties: In C# since 1.0
  • Null handling: In C# 2.0 with nullable types and according operators
  • List/Map syntax: In C# since 1.0 with Indexers
  • Extension methods: In C# since 3.0. See here, but C# is going much further with LINQ
  • Method pointers: In C# since 1.0 with delegates. Later extended with anonymous delegates and Lambda Expressions
  • Multiline Strings: In C# since 1.0 with the @-syntax
  • Infer generics: In C# since 3.0 with general type inference

  • ... go go Java! C# is not resting ... 4.0 is in the pipes, offering another truckload of innovation (dynamic capabilities, co-contravariant features for generics, optional parameters (small thumbs up for Java) and named parameters ...)

    Update: The post is discussed at Hacker News.

    Tuesday, December 16, 2008

    UML redefined

    Mona ASCII.gif
    True, a picture says more than thousand words. Yet UML is not a picture but graphically arranged text.

    -- Daniel Tobler (Zühlke LAT)


    Monday, December 15, 2008

    The root of all evil ...

    http://www.sorgonet.com/supercomputing/films/hal9000.gif For years Donald Knuths famous quote was standing:
    Premature optimization is the root of all evil


    But in his recent blog-post Adam Bien is taking it up with Donald Knuth:
    Premature encapsulation is the root of all evil


    In his sweeping post Adam also kills a pattern (seems to be his latest hobby), encompasses leaky abstraction and promotes KISS/YAGNI.

    Interesting read...

    Related Posts Plugin for WordPress, Blogger...