Category Java

[Java] How to debug JVM Crash

I admit that it is scary. Not only is it outside my comfort zone (Java, because it’s JVM that crashed) but also because it was thrown back to me in SIGBUS from a OS-specific library. But here’s the steps I took to debug the error. Step 1: Retrieve a copy of JVM error report hs_err_pid<xxxxx>.log generated […]

What happens when you assigned state to a Stateless Session Bean?

It’ll probably result in an EJBTransactionRolledbackException caused by a NullPointerException Here’s a scenario that illustrate above possibility T1 | T2 1) setupState [A] | <- store state as a variable | in bean instance [A] | 2) setupState [A] <- [A] is free, so the container | allocate it to server T2 request | 3) […]

JSR 303 – Bean Validation – Let Your Bean Validate Itself

This is a simple application of my previous post whereby you can develop your own validation rule and enforcer. The significance of this application is the use of SelfValidate interface to enable bean to define its own validation method and validator to invoke bean’s method. Typically this constraint is apply to a type, but application […]

JDBC Transaction without EJB

EJB 3 is simple enough that delegating transaction management to it only cost little in creating and annotating an EJB business interface method. However, if you want to skip EJB altogether yet ensure all queries get executed inside a transaction, here’s a quick way: 1. Create a DAO method in which you set JDBC connection’s […]

JSR 303 – Bean Validation – Custom Constraint

So far, we have learn the basic and a not-so-common nested usage of JSR 303 Bean Validation, it’s time to learn how the declarative validation rule was implemented. In another word, we will learn to create a custom constraint this this post. Constraint Annotation Custom constraint is a special kind of annotation that is itself annotated […]

JSR 303 – BEAN VALIDATION – Nested Validation

Following up from my previous post about JSR 303 – Bean Validation, we will see how to apply it to any nested property and how to display validation error on screen using Spring MVC’s JSP tags 1. Bean Validation on Nested Property Recall that to validate any property, we only need to put a Constraint annotation […]

JSR 303 – Bean Validation – Basic

JSR 303 – Bean Validation is defines a metadata model and API for JavaBean validation. The metadata is primarily in Annotation forms, with the possibility of being overridden or extended by XML descriptors. Hibernate Validator is the reference implementation of JSR 303. The current version, as of August 2nd, 2012, of JSR303 is 1.0, and of  Hibernate […]

Spring MVC – SessionAttributes annotation

Spring MVC’s SessionAttributes has 2 parameters: values (storing attributes’ names) and types (storing attributes’ types). It’s pretty straightforward for values. You specify the name of your attribute and it is remembered. It’s trickier for types. For example: – @SessionAttributes (types= java.util.List.class) does not work! – But @SessionAttributes (types= java.util.ArrayList.class) works (but not always) The reason […]

SCBCD – Q & A

Q: Enterprise bean’s external dependency (SessionContext, MessageDrivenContext, other enterprise beans…) must be explicitly declare ? – Seem to. Q: All annotation defined in javax.ejb package? – Not all. Security annotations (such as RunAs, DeclareRoles) are defined in javax.annotation.security); Persistence annotation defined in javax.persistence. PostConstruct, PreDestroy defined in javax.annotation. Q: In Stateful Session Bean, ejbCreate is […]

SCBCD – Quick Rules

Quick Rules – Most “special” methods in EJB can have any access qualifier (public, protected, private or default). – Getter and Setter method of JPA Entity must be either public or protected – All “special” methods CANNOT be final or static – All enterprise bean must be public, top level class, have a default constructor. […]