Monthly Archives: August 2005

I recently had to change some usernames into another one in our [CVS repository][1]. I couldn’t find any information about it using [Google][2], so I tried to figure out how the usernames are stored in CVS on the different commits. [Luckily][3] the usernames are stored in clear text at top of each CVS file. It only took a simple command, to search/replace all usernames with another.

find ./ -type f -exec sed -i ’s/author OLDUSERNAME;/author NEWUSERNAME;/g’ {} \;

The reason I search for “auther USERNAME;” is that this are almost unique. If I’d just search for USERNAME I could have replace important words if the username were generic enough (like replace username ‘ac’ with another one DO couse a lot of trouble, take my word ;-) )

[1]: http://cvs.frifinans.dk/
[2]: http://www.google.com/
[3]: http://en.wikipedia.org/wiki/Luck

While I was searching google for some helpful information about the many [Exception I've tend to get these days][1], I stumble apon this [helpful blogentry][2] about [JBoss][3] and Performance. It said, that by adding a single line in a configuration fil, the performance would increase dramtically. “Yeah right” I thought, and tried it out anyway:

JBOSS_HOME/server/CONFIGURATION/conf/log4j.xml:

into:

JBOSS_HOME/server/CONFIGURATION/conf/log4j.xml:

And the effect was there right after a shutdown/start of the JBoss server. Is was very much faster! Very nice.

After thinking about it, it also made sence. JBoss enables debug logging as default. All the IO required to save this log information uses up A LOT of the performance.

This actually fixes one of my tasks for [FriFinans 0.2][4] :D

[1]: http://billen.dk/2005/08/04/new-jboss-ejb3-release/
[2]: http://fishbowl.pastiche.org/2005/04/19/fun_with_jboss_performance
[3]: http://www.jboss.org/
[4]: http://wiki.frifinans.dk/Roadmap#Version_0.2

I have upgraded my development environment to [JBoss EJB3 RC1][1]. This is apparently more strict and correct according to the [EJB3 spec][2]. This is great, because it helps fixing all that “ugly code ™”. In the next couply of posts I’ll be addressing some of the funny little Exceptions, which I receive while converting the existing [FriFinans][3] code into shiny pebbles ;-) .

The first one is

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

at org.frifinans.server.stateless.UserSettingsBean.get()Lorg.frifinans.server.entity.LedgerUserSetting;(Unknown Source)

This one has a simple solution. I was trying to cascade persist an object, which was already persisted. This is a little piece of the [UserSettingsBean][4] SessionBean, which tried to persist:

public LedgerUserSetting get () {
    LedgerUserSetting lus = new LedgerUserSetting ();

    CommonUser user = ur.getCurrent ();
    if (user != null) {
        // Find user setting
        LedgerUserSetting l = null;
        try {
             l = (LedgerUserSetting) manager.
                    createQuery (
                    "FROM " +
                    "   LedgerUserSetting lus " +
                    "WHERE " +
                    "   lus.user = :user ").
                    setParameter ("user", user).
                    getSingleResult ();
        }
        catch (EntityNotFoundException e) {
            // Ok
        }

        if (l != null) {
            lus = l;
        }
        else {
            lus.setUser (user);
            manager.persist(lus);     // < --- Try to persist (this is ok)
        }
    }

    return lus;
}

The problem was in the [LedgerUserSetting][5] EntityBean, where this following code caused the Exception:

@OneToOne (cascade = CascadeType.PERSIST)   // We shouldn't cascade
@JoinColumn (name = "username")
public CommonUser getUser ()  {
    return user;
}

Remove the cascade option and we end up with:

@OneToOne  // Thats more like it.
@JoinColumn (name = "username")
public CommonUser getUser ()  {
    return user;
}

[1]: https://sourceforge.net/project/showfiles.php?group_id=22866&package_id=132063&release_id=346762
[2]: http://www.jcp.org/en/jsr/detail?id=220
[3]: http://cvs.frifinans.dk:8080/viewrep/FriFinans/frifinans
[4]: http://cvs.frifinans.dk:8080/viewrep/FriFinans/frifinans/src/org/frifinans/server/stateless/UserSettingsBean.java?r=1.6
[5]: http://cvs.frifinans.dk:8080/viewrep/FriFinans/frifinans/src/org/frifinans/server/entity/LedgerUserSetting.java?r=1.5