Tag Archives: Java

Memory leak with Spring integration test context caching

I’ve recently had to debug another out of memory with our Spring integration tests. The tests are configured to create a heapdump on out of memory so I loaded it up with the Eclipse Memory Analyser and this is what … Continue reading

Posted in Java, Spring, Testing | Tagged , , | Leave a comment

Enforcing Spring role based security with a custom PMD rule

Spring makes it easy to have role based security with its @PreAuthorize annotation. But how do you make sure that developers remember to add a security annotation? I like using PMD to do static analysis checks on our code and … Continue reading

Posted in Java, PMD, Spring, Static Analysis | Tagged , , , | Leave a comment

Hibernate Best Practices – using sequences for bulk inserts

For many database tables, an auto increment column is used for the primary key. This is fine for inserting single values, but if you want to bulk insert hundreds or thousands of values and you need to refer to the … Continue reading

Posted in Hibernate, Java, Uncategorized | Tagged , | Leave a comment

Java XML processing with JAXB and special characters

When processing XML, it is important to understand that there are two kinds of special characters: Characters that are permitted, but must either be escaped or inside a CDATA block. Control characters that are not permitted at all. Characters that … Continue reading

Posted in Java, XML | Tagged , | Leave a comment

Hibernate internals – how does pagination work?

Hibernate supports pagination for all query types – HQL, Criteria and SQL, via the query setMaxResults() and setFirstResult() methods, but how does this work under the covers? Well, assuming your database supports it, it will add a row_number() to your … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Memory leak with TestNG and Spring DirtiesContext annotation

We recently added some new integration tests to our test suite. All three tests were Spring integration tests. Normally in a Spring integration test, the entire code for a test method operates in a single transaction, and at the end … Continue reading

Posted in Java, Testing, TestNG | Tagged , , | Leave a comment

IntelliJ Hints and Tips

Most useful keyboard shortcuts (these are for Mac): CMD + O Open class CMD + SHIFT + OOpen file CMD + F Find in file CMD + R Replace in file CMD + SHIFT + F Find in path CMD … Continue reading

Posted in IntelliJ, Java | Tagged , | Leave a comment

log4j in maven tests

If you want to specify log4j configuration when running tests via Maven, you can do so by updating the Maven surefire plugin configuration to point to a specific log4j configuration file. For log4j v2 the appropriate parameter is called log4j.configuration. … Continue reading

Posted in Java, Maven | Tagged , | Leave a comment

Generating code with JavaPoet

Why write code when you can generate it? There are lots of situations when it makes more sense to generate. In this article I’m going to work through an example of how to use JavaPoet and Apache BeanUtils to write … Continue reading

Posted in Java, Uncategorized | Tagged | Leave a comment

Java 8 Streams Tutorial

In this tutorial, I’m going to start by explaining some of the basics of streams. Viz: What streams are Terminal and non-terminal operations Their “lazy” nature Their read-once nature Why they were introduced i.e. how they enable easy parallel operations … Continue reading

Posted in Java | Tagged , | Leave a comment