pagetop
Javablog
by Java coders, for Java codersRSS

Creating an Index with Hibernate

January 4th, 2010 by Sam

The job of creating a SQL Index is rightly the job of a DBA. However, sometimes the need for an index is blindingly obvious and only a mad DBA would miss the opportunity to create a lookup.

Unfortunately, annotations for index hinting did not make it into the JPA 2 specification.

In this post we’re highlighting a Hibernate annotation - @org.hibernate.annotations.Index - that hints for the creation of an index on various columns.

Read on… »



 

@OneToMany Fixes in JPA 2

December 27th, 2009 by Sam

JPA 2 has been released as a part of J2EE 6. Along with many welcome new features, JPA2 has addressed several oversights in @OneToMany Collection mapping, including:-

  • Delete Orphans - where mappedBy entities would persist when deleted.
  • Collections of primitive, core or @Embeddable types - not allowed in JPA 1.

This post shows how Hibernate currently works around these oversights and how the JPA 2 annotations will replace the need for workarounds.

Rock solid implementations of JPA 2 are not yet present, but it will not be long before a stable version of Hibernate 3.5 is available. Be warned that EclipseLink 2.0.0 does not support optional = false and Hibernate 3.5.0 Beta 2 does not support orphanRemoval = true. Please vote/comment on the linked issue reports in order to ensure they are fixed with priority.

Read on… »



 

Tomcat is Dead, Long Live Glassfish!

December 26th, 2009 by Sam

SUN finished off 2009 with a release of Glassfish v3 - a high visibility Open Source implementation of Java Enterprise 6 - and the NetBeans 6.8 IDE.

Combined, these releases significantly reduce the barrier to entry for writing and deploying Java Enterprise applications. However, the documentation is sparse at best, and misleading at worst (some cases in point). This post documents getting Glassfish running with sensible parameters - unlike the defaults - covering:-

  • Admin panel with secure connection and password
  • mod-jk delegation from Apache
  • Enabling the Security Manager
  • Registering a PostgreSQL JDBC connection through JNDI
  • Hibernate to access the JNDI via JPA, whilst allowing persistence in J2SE main methods and tests.

Glassfish is much easier to configure than the perplexing Servlet Container, Apache Tomcat. With support for Ruby on Rails and PHP Web Applications, there is no good reason why anybody should still be using Tomcat - if anything, you should be asking yourself why you’re still using Apache HTTPD!

Read on… »



 

Book Review - Debug It!

December 13th, 2009 by Sam

“Debug It!” (UK) is more than a book on debugging best practices - it’s a motivational tool that succeeds in making debugging sound like fun.

Full of humorous and insightful anecdotes, the main message is “nobody writes perfect code - this is how you deal with it”.

Read on… »



 

Reducing Java Boilerplate

October 20th, 2009 by Sam

One of the darker sides of Java is the boilerplate; lines and lines of boring, repetitious and ugly boilerplate. In this post, we show how to reduce/hide boilerplate and increase the readability of your Java code under the following circumstances:

resulting in making your code more coherent .

Read on… »



 

Experimental Java Hints in NetBeans

October 19th, 2009 by Sam

Users of NetBeans can now install the developer’s Experimental Java Hints in the plugin menu. These are hints that will highlight regions of code with a suggested change. Among others, the package for Netbeans 6.7 will enable hints to:-

  • Better support for static imports issue 89258
  • Auto-generate serialVersionUID data member and value issue 70746

For Netbeans 6.7, simply add

http://deadlock.netbeans.org/hudson/job/release67-contrib/lastStableBuild/artifact/updates.xml

to the Plugins list and do a refresh to see it in the list. After the installation/restart, you can enable the hints you find interesting using the Preferences -> Hints -> Java -> Experimental menu.

A special thanks to Jesse Glick for setting up both the release67 branch of the contrib repository and the hudson builder. Hopefully we’ll see something similar when 6.8 is released.



 

Contributing to NetBeans

April 11th, 2009 by Sam

NetBeans is my IDE of choice and I was recently accepted as an approved contributor on the back of the Java Completion Excluder:

Exclude classes from appearing in the code completer (such as sun.* and sunw.*) with method-level granularity. Example use case: java.lang.Object.{wait*, notify*, clone, finalize} have more appropriate alternatives so allow the user to disable the completer from acknowledging their existence.

In this post, I’ve documented my initial experience of contributing to NetBeans, in the hope that it will lesson the barrier of entry and inspire readers to consider doing the same!

Read on… »