Building a Java EE Application with JPA and EclipseLink in NetBeans

NetBeans IDE remains a preferred tool for many Java developers in Australia, particularly those working in Sydney's bustling financial district and Melbourne's growing startup scene. Its tight integration with Java EE standards, combined with sensible code generation, makes it well suited to teams building line-of-business applications against relational databases. When the requirement calls for object-relational mapping with strong tooling support, JPA paired with EclipseLink is a dependable choice that has shipped with NetBeans for years.

The combination of JPA and EclipseLink lets you map Java classes to database tables using annotations rather than verbose XML descriptors. For Australian developers maintaining systems that interact with APRA-supervised reporting databases or local council records, this approach reduces boilerplate and keeps the entity model close to the domain. NetBeans recognises EclipseLink as the default persistence provider when you create a new Java EE project, so the scaffolding work is minimal.

This walkthrough takes you through project creation, persistence setup, entity modelling, session bean wiring, and deployment. Along the way, it touches on documentation habits that suit teams operating under the Privacy Act 1988 and the Notifiable Data Breaches scheme, where every layer of an enterprise system needs a clear audit trail.

Setting up the project and configuring the runtime

Start by creating a new project in NetBeans through File → New Project → Java with Maven → Java EE 8 Application. Pick an appropriate application server; developers working in Brisbane often default to GlassFish or Payara because of the strong local Jakarta EE community in Queensland, while those targeting enterprise clients in Perth's resources sector may prefer WildFly for its robust clustering. Whichever you choose, NetBeans handles the deployment descriptor and the pom.xml changes behind the scenes.

After the project is created, right-click the Libraries node and confirm that EclipseLink is listed. If you need additional tooling, the plugin guide for NetBeans walks through adding a custom module that can extend the IDE's database exploration features. A clean project tree at this stage typically contains an EJB module, a web module, and a shared library module where entities will live.

Before writing any entity classes, decide on the database. For local development, an in-memory H2 instance is fine, but anything bound for production in Australia should connect to PostgreSQL or Oracle, both of which are common in government and finance deployments. Set up a dedicated database user with the minimum privileges required, and document the connection details in a properties file that is excluded from version control.

Configuring the persistence unit

A persistence unit is the bridge between your Java entities and a concrete database connection. Create a persistence.xml inside the META-INF folder of the EJB module and define the unit with EclipseLink as the provider. A minimal unit declares the datasource JNDI name, the transaction type, and a list of annotated classes that NetBeans can scan at compile time.

The choice of application server shapes how the datasource is registered. A quick side-by-side helps clarify the trade-offs:

Server Java EE support EclipseLink bundling Typical Australian use case
GlassFish Jakarta EE 8 reference impl Bundled, version-locked Training, university courses, NSW government pilots
Payara Jakarta EE 8, active support Bundled, patched monthly Sydney fintech production deployments
WildFly Jakarta EE 8 via patch Provided as a subsystem Perth mining-tech, Melbourne telco backends

Once the unit is registered, run a quick connection test from inside NetBeans by right-clicking the project and choosing Run. The output window should report that EclipseLink has initialised the schema or, if you prefer, left the schema generation to a migration tool. Keeping schema generation in the hands of Flyway or Liquibase is the safer pattern for systems that must align with the Australian Cyber Security Centre's Essential Eight maturity model.

Modelling entities with JPA annotations

Entity classes are ordinary POJOs annotated with @Entity. NetBeans provides a New → Entity Class wizard that asks for a table name, a primary key strategy, and the columns you want to expose. Generating the skeleton this way ensures getters and setters follow JavaBean conventions, which is essential for frameworks that rely on reflection.

For a customer record, you might annotate an ID field with @Id and @GeneratedValue(strategy = GenerationType.IDENTITY), then add @Column mappings for names, addresses, and the Australian Business Number when relevant. Use @Enumerated(EnumType.STRING) for any field backed by a fixed set of values; this keeps the database readable and avoids the ordinal surprises that plague teams maintaining legacy systems. If your entities need to expose methods for downstream consumers, the JavaDoc generation workflow explains how to keep API documentation in step with code changes.

Relationships are where EclipseLink shines. A one-to-many mapping between an Order entity and a list of LineItem objects is written in a few lines, and the IDE flags common mistakes such as a missing mappedBy attribute or a bidirectional fetch that would trigger an N+1 query. Run a quick JPQL preview from the IDE's SQL window to confirm the generated SQL matches what you would write by hand.

Session beans and service layer

A stateless session bean is the natural home for business logic that wraps entity operations. Create one with New → Session Bean, pick a remote or local interface based on whether the web tier sits in the same container, and inject the EntityManager with the @PersistenceContext annotation. Method-level transactions can be controlled with @Transactional or the older @TransactionAttribute from the EJB specification.

For workflows that need to track state across multiple requests, a stateful session bean is appropriate. Examples include a shopping cart that persists between page views or a multi-step onboarding flow used by HR teams processing staff across Adelaide and Darwin offices. The mechanics of invoking such a bean from a servlet or a REST resource are covered in a stateful bean example, which shows how the container handles passivation and activation.

Keep the service layer thin and focused on orchestration. Validation belongs in the entity using @NotNull and @Size from Bean Validation, while logging belongs in an interceptor registered through @InterceptorBinding. This separation pays off when auditors ask how a particular change was recorded, because each concern has a single, traceable home.

Deploying and observing the application

Deployment is a right-click operation in NetBeans once the server is registered. Watch the server log for the EclipseLink banner and any warnings about lazy initialisation. In production-like environments common to Australian banks, set the log level to FINE during development and reduce it to WARNING before promotion.

Use the NetBeans profiler and the built-in HTTP monitor to trace requests through the session bean layer and into the database. A well-tuned application shows single SQL statements per repository method, with no chatty logging spilling Personally Identifiable Information into shared log files. Local habits matter here: many Sydney-based teams keep a Friday afternoon ritual of reviewing the week's profiling snapshots over a flat white, catching performance regressions before they reach the change advisory board.

Once deployed, document the build, the deployment procedure, and the rollback path in the project's wiki. Clear documentation is the kind of quiet discipline that keeps a Java EE application maintainable long after the original author has moved on to the next project.