Finally i started working on unit tests and already got a gotcha on eclipse galileo with jMock 2.5.1.
Galileo Ships with jUnit 4 but unfortunately without org.hamcrest.TypeSafeMatcher which is needed by jMock.
Adding jMock through Maven still leaves the Problem with Classpath and who comes first.
I tried the following links with no luck:
http://www.southsearepublic.org
http://cedar715.wordpress.com/2009/10/20/86/
Then i removed jUnit Libraries in Project Properties under Java Build Path => Libraries and added jUnit through Maven Dependencies.
Works like a charm now.
Tuesday, August 17, 2010
Tuesday, July 27, 2010
jPitfalls - Enums in Hibernate
In Hibernate you have two ways defining the association between database fields and Java properties. You can use xml definitions or Annotations.
I for example started with xml and later changed everything to Annotations. Either way, i used jBoss Hibernate Tools in Eclipse for generating the Java Class Files and xml Configuration.
Fortunately both Database and Java have Enums. Unfortunately the Hibernate Tool does not. (don't get me started on Hibernate at this point) So while you may think "Hey, i used Enums in my Database Design because i am a genius" and "That's great, now i can use them in Java" you can't. (Who is the genius).
Using Annotations it's easier. Creating Enums, adding them into the Hibernate Class Files and voila, you have Enums. (But don't forget to maintain them = meaning if you change the Enum in Java or the Database you have to change the other Part two by hand).
Using xml is a complete different Story. You have to Define the Type and adjust it by Hand. There is even a GenericEnumUserType explained in the jBoss Community.
In the end i still think that it should also be possible to create Enums automatically and some day it might, but in the meantime stay sharp and check you Enums.
Linktipps:
http://community.jboss.org/wiki/Java5EnumUserType
http://weblog.dangertree.net/2007/09/23/mapping-java-5-enums-with-hibernate/
I for example started with xml and later changed everything to Annotations. Either way, i used jBoss Hibernate Tools in Eclipse for generating the Java Class Files and xml Configuration.
Fortunately both Database and Java have Enums. Unfortunately the Hibernate Tool does not. (don't get me started on Hibernate at this point) So while you may think "Hey, i used Enums in my Database Design because i am a genius" and "That's great, now i can use them in Java" you can't. (Who is the genius).
Using Annotations it's easier. Creating Enums, adding them into the Hibernate Class Files and voila, you have Enums. (But don't forget to maintain them = meaning if you change the Enum in Java or the Database you have to change the other Part two by hand).
Using xml is a complete different Story. You have to Define the Type and adjust it by Hand. There is even a GenericEnumUserType explained in the jBoss Community.
In the end i still think that it should also be possible to create Enums automatically and some day it might, but in the meantime stay sharp and check you Enums.
Linktipps:
http://community.jboss.org/wiki/Java5EnumUserType
http://weblog.dangertree.net/2007/09/23/mapping-java-5-enums-with-hibernate/
Wednesday, July 07, 2010
jPitfalls - log4j adding through maven
One of the first thing a developer want to add is logging. Without logging there is no development. And i mean it... no development.. seriously!
Therefore i looked up in the net which logging Facility i should use and ended up with log4j. (And because all the Tutorials and Books i looked up used it as well). It's really great and flexible. (Enough advertising.)
But being not accustomed to Maven and Dependency Management and everything automatic, i had to learn another hard lesson.
The Thing with log4j is, there are several ways the output can be collected. Console, File, Database, you name it. The Thing with Maven and log4j is, if you add a plugin, it's automatically included and you don't even have to do much more work.
Being accustomed that every little peace has to be configured by hand i was unprepared for the *automaticallywedoeverythingforyou* world. Adding more than one log4j plugin i ended up with no output at all.
Nothing worked and i was starting to gave up my hopes. Fortunately a colleague of mine helped me out (we were sitting together, no clue at all) and found the reason for the misbehavior.
Use only the one output you need, no more than that and everything worked like a charm.
So today's Mantra is "Only use what you need, no more than that" (young grasshopper)
Thanks again
Therefore i looked up in the net which logging Facility i should use and ended up with log4j. (And because all the Tutorials and Books i looked up used it as well). It's really great and flexible. (Enough advertising.)
But being not accustomed to Maven and Dependency Management and everything automatic, i had to learn another hard lesson.
The Thing with log4j is, there are several ways the output can be collected. Console, File, Database, you name it. The Thing with Maven and log4j is, if you add a plugin, it's automatically included and you don't even have to do much more work.
Being accustomed that every little peace has to be configured by hand i was unprepared for the *automaticallywedoeverythingforyou* world. Adding more than one log4j plugin i ended up with no output at all.
Nothing worked and i was starting to gave up my hopes. Fortunately a colleague of mine helped me out (we were sitting together, no clue at all) and found the reason for the misbehavior.
Use only the one output you need, no more than that and everything worked like a charm.
So today's Mantra is "Only use what you need, no more than that" (young grasshopper)
Thanks again
Subscribe to:
Posts (Atom)