Skip to content

Author Archives: Priyatam

Understanding OpenJPA InvalidStateException: Detected reentrant flush

Ran into this issue today: <openjpa-1.2.2-r422266:898935 fatal user error> org.apache.openjpa.persistence.InvalidStateException: Detected reentrant flush. Make sure your flush-time instance callback methods or event listeners do not invoke any operations that require the in-progress flush to complete. at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1923) at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1698) at org.apache.openjpa.kernel.QueryImpl.isInMemory(QueryImpl.java:956) at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:838) at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:779) at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:525) This is a tricky exception since the verbose [...]

Mock Unit Testing Services and Daos with Mockito and Spring 3

If you haven’t been mocking yet, check this out. There are other tools in Groovy using DSLs but if you want to stick to Java, Mockito is by far the best BDD-style mock unit testing tool. Traditional examples provide a List mocking example or foo/bar example which I find it mostly annoying since it doesn’t [...]

Database Surrogate keys Vs Natural keys

Ran into this issue at my client recently and it was hard to convince the db admin why surrogate keys was an advantage for a developer working in an ORM solution Natural key – business requirements changes, then you have to change the natural key – not easy to index an alphanumeric or String value [...]

Understanding Spring Transaction Management

This is a little wiki file I had for a long time while understanding how spring transactions worked. Time to put it in a blog. (Note: data is unprocessed) – Two types of transactions: Global and Local Transactions – PlatformTransactionManager is main interface in Spring – PROPAGATION_REQUIRED, PROPAGATION_SUPPORTS, PROPAGATION_MANDATORY, PROPAGATION_REQUIRES_NEW, PROPAGATION_NOT_SUPPORTED, PROPAGATION_NEVER, PROPAGATION_NESTED – ISOLATION_DEFAULT, [...]

Maven settings.xml for corporate proxy with custom user-Agent

In some corporate enviroments, it’s just not enough to add a simple proxy setting in maven settings.xml. For instance, some prozy servers reject any HTTP request that’s coming from a non IE browser. Foruntately, Maven has a way to fake a user-agent and this might be a way to circumvent your corporate server settings Of [...]

Understanding Events in JEE6 with examples

JEE 6 implements Event Delagation model and Observer (Publish-Subscribe) pattern out of the box much more elegantly than other api. A Publisher fires events along with a type that needs to be passed. An Observer (can have multiple observers) simply observes for the Event “type” and receives the object sent by the publisher along with [...]

Understanding JSR299, Contexts and Dependency Injection explained

Forget Session, Application, Request, and Coversation Scope. All these scopes, though useful, still have to be managed by hand. ie., – a reference must be created in a session or request (the context) – a utility method must be written to manage this context (& cleanup eventually) – the component needs to have access to [...]

Understanding the uses of JEE6 @Decorator vs @Interceptor with an example

Let’s look at an Interceptor first. Interceptor definition: AuditTime — wraps a simple debug around a method invocation with time stamps. import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; import java.lang.annotation.*; import javax.interceptor.*; @Inherited @InterceptorBinding @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface AuditTime { } Interceptor implementation. import javax.inject.*; import javax.interceptor.*; import org.jboss.logging.*; @AuditTime @Interceptor public class AuditTimeInterceptor implements [...]

Ivy file for a JEE6 / Seam 3-beta / Primefaces project

Most examples online use Maven for build files. I’m sure some of you are still on ant or Ivy. Here’s an ivy file for a starter JEE6 project with Seam-3-beta (at this time of writing), Primefaces, Prettyfaces and other misc jars (testng) that you might need. <?xml version="1.0" encoding="ISO-8859-1"?> <ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"> <configurations> <conf [...]

Example of RESTful Webservices in JEE6 with Exception mapper to route HTTP status codes

JEE6 provides a specification for Webservices (SOAP AND REST) and JAX-RS is the default Reference implementation. A lot of cookie-cutter code is eliminated for implementing webservices. Unlike Restlet which doesn’t provide much functionality for integrating restful webservices into a web application (exception mapping and custom annotations to process http params, or DI), JEE6 webservices combine [...]