Hibernate 4.0.1 Final and Jenkins 1.449 java.lang.NoSuchFieldError: TRACE

Using Hibernate 4.0.1 Final within a Jenkins plugin causes the error below. This is because Jenkins ships with log4j 1.2.9 and Hibernate requires 1.2.16

Replace the old jar with the new in {jenkins_home}/WEB-INF/lib and Hibernate will work.

java.lang.NoSuchFieldError: TRACE
	at org.jboss.logging.Log4jLogger.translate(Log4jLogger.java:64)
	at org.jboss.logging.Log4jLogger.doLog(Log4jLogger.java:44)
	at org.jboss.logging.Logger.trace(Logger.java:128)
	at org.hibernate.ejb.internal.EntityManagerMessageLogger_$logger.trace(EntityManagerMessageLogger_$logger.java:422)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:322)
	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
	...
        Your classes
        ...
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
	at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:700)
	at hudson.model.Build$RunnerImpl.build(Build.java:178)
	at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
	at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:470)
	at hudson.model.Run.run(Run.java:1404)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
	at hudson.model.ResourceController.execute(ResourceController.java:88)
	at hudson.model.Executor.run(Executor.java:238)
Posted in Programming | Tagged , , | 1 Comment

The INSERT permission was denied on the object ‘X’, database ‘Y’, schema ‘Y’.

Can be caused by overzealous addition of permissions. Make sure the Role Members ‘db_denydatawriter’ and ‘deny_datareader’ are unchecked.

MSSQL User Permissions

Posted in Programming | Tagged | 2 Comments

Connect To HyperSQL Database Via SqlTool

The following command executed in the lib directory of the HyperSQL tool will connect to a HyperSQL database:

java -cp sqltool.jar;hsqldb.jar org.hsqldb.cmdline.SqlTool --inlineRc url=jdbc:hsqldb:file:path_to_db\db_name

Remember to run commit; before exiting the tool as any statements you run will not be committed until you do.

Posted in Programming | Tagged , | 1 Comment

HyperSQL SqlTool: Header has X columns, but input record has Y column values

I received the following error when attempting to import data into HyperSQL via the bundled SqlTool from a CSV file generated by MSSQL Server.

Header has 17 columns, but input record has 14 column values

Normally this indicates just what it says, that the header of the DSV specifies a different number of columns from the number indicated in the value line. In my case however I did have the correct number of columns.

The column that was giving the problem contained JavaScript. I thought the semi-colons or parenthesis may be the cause but they had no effect. The error was caused by newline characters in the JavaScript. After removing these the import worked.

Example of data causing the error:

0|Some text|var count = 5;
1|Some more text| if(util.isSomething()) {
    result = 'Something';
} else {
    result = 'Nothing';
}
2|Even more text|var count = 4;
Posted in Programming | Tagged , , , | Leave a comment

Amazon EC2 Elastic Beanstalk Basic Authentication

I wanted to set up a secure update center for a NetBeans Platform application Tetrad IT is working on. I also wanted to play with Amazon EC2…

As the update center is for Tetrad staff only I wanted to do the simplest thing that would work, so I used the MemoryRealm to store user credentials in Tomcat. I also wanted to be able to update the user credentials by deploying the WAR and not have to mess about with the Tomcat configuration files.

For the impatient, the EC2 specific portion of the setup is here.

Tell your application it needs security
To tell you web application how to secure itself you configure the web.xml.

The security-constraint section tells the application to allow only users with the role netbeans-application to access the updates folder. The login-config section indicates that basic authentication is to be used. security-role defines the role we’ll be using.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <security-constraint>
        <display-name>UserConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>UserConstraint</web-resource-name>
            <description/>
            <url-pattern>/updates/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>netbeans-application</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>file</realm-name>
    </login-config>
    <security-role>
        <description>NetBeans Platform application role</description>
        <role-name>netbeans-application</role-name>
    </security-role>
</web-app>

Who gets through security
Normally you would edit the tomcat-users.xml file in the Tomcat conf directory. Instead we’ll create a users.xml file in the web application WEB-INF directory. This file contains the credentials of the users who will be given access to the updates directory.

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
    <role rolename="netbeans-application"/>
    <user username="user1" password="password" roles="netbeans-application"/>
    <user username="user2" password="password" roles="netbeans-application"/>
    <user username="user3" password="password" roles="netbeans-application"/>
</tomcat-users>

Where to find the users
Your application is not looking for the user credential information in users.xml by default. To show your application where to find the user information create the file context.xml in the META-INF directory of your web application.

The important part to note is the pathname attribute. As far as I can tell it needs to be an absolute path as all non absolute paths are relative to the Tomcat directory. This particular path is specific to the Elastic Beanstalk default setup.

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/EC2Example">
    <Realm className="org.apache.catalina.realm.MemoryRealm" pathname="/opt/tomcat7/webapps/ROOT/WEB-INF/users.xml"/>
</Context>

Wrapping up
Your web application structure should look something like this:

Web application structure

Web application structure

Pointing your NetBeans Platform application toward the secure update center should result in you being asked for a username and password:

Update Center Authentication Popup

Update Center Authentication Popup

Posted in Programming | Tagged , , , , , , | 3 Comments

I’ll Be Speaking At SAOUG 2011

I’ll be speaking at the SAOUG 2011 conference (13 – 15 November) in Sun City:

“Implementing an Automated Review for Siebel”

It should be great fun, and if you’re into Java or Oracle products it’s the place to be. See you there 🙂

SAOUG 2011 Conference Agenda

SAOUG 2011 Conference Agenda

Posted in IT | Tagged , , | Leave a comment

Johannesburg Siebel User Group October 2011 – Exadata

Bill Flannigan from Risctec will be showing us the ins and outs of Oracle’s Exadata Database Machine:

“The Oracle Exadata Database Machine is the only database machine that provides extreme performance for both data warehousing and online transaction processing (OLTP) applications, making it the ideal platform for consolidating onto grids or private clouds. It is a complete package of servers, storage, networking, and software that is massively scalable, secure, and redundant. With Oracle Exadata Database Machine, customers can reduce IT costs through consolidation, manage more data on multiple compression tiers, improve performance of all applications, and make better business decisions in real time.”- http://www.oracle.com/us/products/database/exadata-database-machine/index.html

This is not a sales pitch! Bill has experience with Exadata and you’ll get the views of someone who’s had to implement this technology in the real world.

Oracle is sponsoring a book giveaway! “Achieving Extreme Performance with Oracle Exadata”. Bring a guest to the evening and get an extra chance to win.

Location: Chillroom – Internet Solutions – Le Mans Building – The Campus – Cnr Sloane and Main

Date: 03 October 2011

Agenda:
17:30 – 18:00 Drinks and socializing
18:00 – 18:45 Presentation
18:45 – onward Pizza, drinks and socializing

Sponsors for the evening are Tetrad IT. Please RSVP to events@jsug.co.za, the Facebook group or Meetup.com

You can find the group on:

Posted in IT | Tagged , , , | Leave a comment

September Jozi JUG – Scala Introduction

If you’re in the Johannesburg area, come check out the Jozi JUG!

Monday’s Jozi JUG session will be on Scala! Mitchell Wong Ho, Scala enthusiast and founder of the SA Scala User Group, will give us an introduction to the language. It should be great fun.

Time: 26/09/2011 17:30 for 18:00
Location: Scrooge Diner, Brightwater Commons, Republic Road, Randburg
Agenda:
17:30 – 18:15 Drinks 🙂
18:15 – 19:00 Scala presentation
19:00 onward Supper and networking

Please RSVP on Facebook or Meetup.com

Sponsors for the evening are Enerweb.

We’ll also be giving away electronic copies of ‘Seven Languages in Seven Weeks’. (Sponsored by Tetrad) Bring a guest and stand an extra chance to win.

Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (Pragmatic Programmers)

Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (Pragmatic Programmers)

Posted in IT | Tagged , , , , | Leave a comment

Windows Mobile 6 Application File Associations

In order for your Windows Mobile application to be invoked when a user opens a particular file type, you need to create an association between the file type and your application. This is done through registry entries.

I’m developing a Windows Mobile 6 application, so my development environment is Visual Studio 2008. The steps below show how to associate a custom file type (.cstm) to your application.

1. Right click on your CAB project. Select View > Registry

Open Registry Editor on CAB project

Open Registry Editor on CAB project

2. Under HKEY_CLASSES_ROOT add Key “.cstm”

3. Under “.cstm” add String values:

        Content Type        text/cstm
        Default             cstmfile
        PerceivedType       text
cstm Registry Entry

cstm Registry Entry

4. Under HKEY_CLASSES_ROOT add Keys “cstmfile” > “Shell” > “Open” > “Command”

5. Under Command add String value:

        Default             ""%InstallDir%\CABExample.exe"" %%1

Note the double quotes surrounding the path to the exe and the percentage characters. Visual Studio creates an inf file and generates the CAB from that. In order for the inf file to be properly formed we need to escape special characters by adding two special characters for every one we want to appear i.e. “” in Visual Studio becomes ” in the devices registry. %InstallDir% is an exception as that is replaced by the actual installation directory at install time.

Open Command Registry Entry

Open Command Registry Entry

6. Under HKEY_CLASSES_ROOT add Keys “cstmfile” > “Shell” > “OpenDoc” > “Command”

7. Under Command add String value:

        Default             ""%InstallDir%\CABExample.exe"" %%1
OpenDoc Command Registry Entry

OpenDoc Command Registry Entry

When you build your project, the following should appear in your inf file:

[RegKeys]
"HKCR",".cstm","Content Type","0x00000000","text/cstm"
"HKCR",".cstm","Default","0x00000000","cstmfile"
"HKCR",".cstm","PerceivedType","0x00000000","text"
"HKCR","cstmfile\Shell\OpenDoc\Command","Default","0x00000000","""%InstallDir%\CABExample.exe"" %%1"
"HKCR","cstmfile\Shell\Open\Command","Default","0x00000000","""%InstallDir%\CABExample.exe"" %%1"

When you install the CAB file on the device, the registry entries will be made and your application will be associated with the file type.

Posted in Programming | Tagged , , , | 1 Comment

Making JGoodies Easier With Client-Objects

JGoodies is a selection of easy to use libraries for GUI development. One of which is JGoodies Binding. This allows you to bind your UI components to your domain objects and have changes in one reflected in the other.

You'd have to be a basket case not to automate - Image from drogpatravel on Flickr

You'd have to be a basket case not to automate - Image from drogpatravel on Flickr

The only downside to using it is the requirement that the POJOs you bind to have support for bound properties. Adding the support, even with the assistance of the JGoodies Model class, is error prone and tedious. Especially if you’re generating POJOs from a database or retrofitting the support to existing classes.

Example of a class where you manually add support:

public class Person extends Model {//Model is a JGoodies class that takes care of some bound properties boilerplate code
    private String name;
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        //Adding this code for every attribute is tedious and error prone.
        String oldValue = this.name;
        this.name = name;
        firePropertyChange("name", oldValue, name);
    }
}

To the rescue comes Client-Objects. This library allows you to dynamically add the property change support to your POJOs at runtime. All the bound property boilerplate code disappears, replaced by a single call that is made after you’ve created the object (manually or through a framewework, for example JPA). Here’s an example of hiding the code behind a utility class:

public class UIBeanEnhancer {
    public static  E enhance(E bean) {
        BeanRegistry.registerType(bean.getClass());
        return BeanEnhancer.addPropertyChangeSupport(bean);
    }
}
Posted in Programming | Tagged , , , | Leave a comment