Dariusz on Software Quality & Performance


JPA + ObjectDB example

Filed under: en — Tags: , , — dariusz.cieslak @

JPA stands for "Java Persistence API" – an API that tries to replace direct Hibernate (or other ORM) usage with more generic layer that allows to replace underlying ORM with no application code changes.

Although ORM (object relational mappers) typically use relational database under the hood JPA is not restricted to relational databases. I'll present how object database (objectdb) can be used using JPA interface.

All the source code can be located here: https://github.com/dcieslak/jee-samples/tree/master/jpa.


Firstly, you have to define your model and relations using POJO with JPA annotations. We try to make model as simple as possible, so no getters/setters pairs if not really required.

class SystemUser implements Serializable {

    @Id @Column @GeneratedValue(strategy=GenerationType.AUTO)
    public Integer userId;

    public String systemUserName;

    public Departament department;

    public String toString() {
        return "SystemUser(" + systemUserName + ", " + department + ")";



ConfigurationException: XML-22101: (Fatal Error) DOMSource node as this type not supported

Filed under: en — Tags: — dariusz.cieslak @

When you setup your project with commons-configuration library plugged in sometimes you can get very misleading error:

ConfigurationException: XML-22101: (Fatal Error) DOMSource node as this type not supported

This error may be caused by missing XML library bindings. In order to fix that error you have to configure properly some service providers (point JVM to correct XML parsing/transformation implementations).



Is Static Typing the Root of All Evil?

Filed under: en — Tags: — dariusz.cieslak @

Anders Janmyr has written recently an interesting article why he hates static typing:

Donald Knuth wrote in his famous paper Structured Programming with go to Statements (PDF)

We should forget about small efficiencies, say about 97% of the time: pre-mature optimization is the root of all evil

Since compilation is premature optimization, it is therefore, the root of all evil. Simple!

Pretty "smart" reasoning but stupid, IMHO.



commons-logging.jar considered harmfull?

Filed under: en — Tags: , — dariusz.cieslak @

During recent 2nd level cache implementation research I noticed EHCache has a very funny dependency: slf4j. Hey, WTH, yet another log library implementation? – I asked myself. No commons-logging as everywhere?

I googled around and found "The evils of commons-logging.jar and its ilk" article. It highlight some problems related to commons-logging usage:

  1. Different commons-logging versions in one project mirrors DLL-hell problem
  2. Collection logs from all sources into one stream has no bigger value for a developer
  3. Advanced configuration is logging back-end dependant (appenders for log4j for example), so unified layer is not valuable here
  4. Configuration is not intuitive and hard

I agree with 1, 3 and 4. 2 is questionable: sometimes logs sorted in one timeline allows for better error analysis.

slf4j is proposed as an alternative. It's more modular and (probably) simpler that commons-logging. All configuration is a matter of placing selected implementation (slf4j-jdk14-1.5.8.jar for instance) jar on classpath. And voila! – logging is done thru JDK 1.4 logging. Quite simple.


How To Debug JNDI Lookup Problems

Filed under: en — Tags: , — dariusz.cieslak @

Sometimes when you get an exception like this:

javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:"

you want to see what entries are visible in JNDI. No problem, place this code somewhere near lookup problem code location:

InitialContext ic = new InitialContext();
NamingEnumeration it = ic.list("java:comp");
System.out.println("JNDI entries:");
while (it.hasMore()) {
    NameClassPair nc = it.next();
    System.out.println("JNDI entry: " + nc.getName());

You will see all JNDI names availailable on console then (you can use your logging library instead of course).

Older Posts »

Powered by WordPress