On Java Development

All things related to Java development, from the perspective of a caveman.

Reconciling ArrayList contents with the Comparator class

without comments

Introduction

This post explains how to use the Comparator class to reconcile the contents of two arraylists. As an example of use, this technique can be helpful when there is a need to know what was changed in a pick list. This information can then be used to log the “who-what-when” questions about the edit session.
Read the rest of this entry »

Written by admin

March 11th, 2016 at 1:20 pm

Persisting Records with Auto Generated Fields

without comments

Introduction

This post shows what can happen when adding records to a file with an identity field and the value of for the field is automatically incremented by the database.

There are certain annotations that need to be made to tell Hibernate not to update that field.

 
 

The SQL Statement Segment

Below is the source segment used to create the table. The Library/FileName is an arbitrary name of the library and file.

The GENERATED ALWAYS AS IDENTITY clause indicates that DB2 will always generate a unique value for the identity column for each row inserted into the table. DB2/400 will issue an error if a value is specified in an insert operation for the identity column defined using this clause. In other words, your Java code should never modify this field. If it does, you should probably expect unexpected consequences for the file.

 
 

The Entity Class

Below is the source segment of the entity class showing the column definition for the identity field

Adding ‘insertable = false, updatable = false’ to the column definition indicates that the responsibility for calculating the sequence number does not belong to the application. DB2/400, or DB2 Universal Database as it is now known, is responsible for maintaining the value for this field. In effect, the field obtains a read only characteristic.

 
 

Errors Generated During Record Insert

Without ‘insertable = false, updatable = false’, when the record is persisted to the database, the following error is generated.

 
 

Resources:

Generating Unique Values in DB2 Universal Database
Apache OpenJPA 2.1 User’s Guide, Chapter 13, Mapping Metadata, Column
IBM Knowledge Center – Apache OpenJPA User’s Guide

Written by admin

November 13th, 2015 at 7:23 am

When to close the EntityManager

without comments

Introduction

The post addresses the question of when to close the JPA Entity Manager. The information presented will show that the answer actually depends on many things, ranging from the use of JSE vs JEE, to how the JTA transaction unit is coded.
Read the rest of this entry »

Written by admin

October 14th, 2015 at 1:23 pm

Posted in JPA

Eclipse Tip – Remove a war File Entry from Eclipse’s Export Dialog

without comments

Introduction

This post shows how to remove a war-file entry from the export dialog used when creating a war-file.

Open this file found in the workspace directory:
.metadata\.plugins\org.eclipse.jst.j2ee.ui\dialog_settings.xml

Locate the section for “Workbench”. At the bottom, you should see the path(s) for the war-files entered when using the export wizard. Remove the offending entry and then save.

Written by admin

June 25th, 2015 at 7:18 am

Posted in Eclipse

Eclipse Tip – Remove a jar file entry from the export dialog

without comments

Introduction

This post shows how to remove a jar file entry from the export dialog used when creating a jar-file.

Open this file found in the workspace root directory:
.metadata\.plugins\org.eclipse.jdt.ui\dialog_settings.xml

Locate the section for “JarPackageWizard”. At the bottom, you should see the names of the jar-files entered when using the export wizard. Remove the offending entry and then save.

Written by admin

June 24th, 2015 at 10:37 am

Posted in Eclipse

JPA Entity Manager Factory, Transaction Manager, Datasource and JNDI Configuration

without comments

Introduction

This post describes the contents of the file “jpaDataSourceContext” found in baseproject. This file contains datasource and JNDI definitions using Spring’s JPA support for Entity Manager Factory, Transaction Manager and Hibernate Adapters. The file is read during the initial phase of the application’s startup processing which occurs when the server is started. This means all data source/JNDI references, used or not, must be present and valid.
Read the rest of this entry »

Written by admin

February 19th, 2015 at 10:52 am

Installing WindowBuilder (Swing/SWT development plugin)

without comments

Introduction

This post shows how to install the Swing/SWT GUI development tool to create applications to be deployed directly onto PCs.
Read the rest of this entry »

Written by admin

January 19th, 2015 at 2:20 pm

Using Java’s Javadoc Tool

without comments

Introduction

This post shows how to use Java’s Javadoc tool to create HTML pages that present information derived from Javadoc annotations.
Read the rest of this entry »

Written by admin

January 14th, 2015 at 6:33 am

Posted in Java Utilities

Managing the Logging of Exceptions

without comments

Introduction

This post shows how to manage the logging of exceptions so that when developing the application the stack trace for the error appears in the Eclipse console. The behavior should change when the application is running on the TEST or PROD server so that the error message is logged to the application’s log file as a fatal error.
Read the rest of this entry »

Written by admin

January 13th, 2015 at 7:20 am

Finding the Jar-file Containing a Known Class

without comments

Introduction

This post shows how to locate that jar-file that contains the class you need to import into your project. This is helpful for those times when you’re writing a custom solution using the jar-files from a 3rd party.
Read the rest of this entry »

Written by admin

December 10th, 2014 at 11:19 am

Posted in Java Utilities