On Java Development

All things related to Java development, from the perspective of a caveman.

Guidelines for Creating JPA POJOs, Interfaces and DAOs

without comments

Introduction

This post presents guidelines to follow when creating JPA oriented POJOs, Interfaces and DAOs and briefly covers naming as well as JPA annotations.

 

POJOs

This section presents guidelines to use when naming and annotating JPA oriented POJOs.

Naming
If the file resides on the iSeries, the name for the POJO should use the capitalized name of the file.

Examples of POJO names representing files on the iSeries:

  • POLBILLP
  • PSPMPOL
  • PSPMRDR
  • PSPTAUD
  • PDFCNTRLP

However, if the file resides outside of the iSeries, file names will often be in the singular, upper case, with underscores to separate the names. Therefore, the name of the POJO should adhere to this name as closely as possible.

For more information about file naming, see the post General Rules of Thumb for Creating Files

Annotations
The following illustrates the annotations for the Entity name, named queries and the table name with which the entity is associated.

These annotations are standard. The only thing here that can vary relates to the name assigned to the @NamedQueries. Names should be prefixed with the name of the POJO/Entity that owns it. For example, for this Entity class (PDFCNTRLP) use this convention for a @NamedQuery: [Entity Name].[Query name]. This results in this name: “PDFCNTRLP.getListOfRecordsByPDFGroupName“. This convention will ensure that the name given to the @NamedQuery will not collide with those given to other Entities.

 

DAO Interface

This section presents guidelines to use when naming and annotating JPA oriented DAO Interfaces.

Naming
If the file resides on the iSeries, the name for the DAO Interface should use the capitalized name of the file.

Examples of DAO Interface names representing files on the iSeries:

  • POLBILLPDao
  • PSPMPOLDao
  • PSPMRDRDao
  • PSPTAUDDao
  • PDFCNTRLPDao

For files of other databases such as DB2, MSSQL, MySQL, etc, use the name assigned to those files. If the name is unacceptably long, then use a surrogate name for the name of the DAO interface.

The following is a JPA oriented DAO interface for file PDFCNTRLP residing on the iSeries.

 

DAOs

This section presents guidelines to use when naming and annotating JPA oriented DAOs which implements the DAO interface.

Naming
If the file resides on the iSeries, the name for the DAO Interface should use the capitalized name of the file.

Examples of DAO Interface names representing files on the iSeries:

  • POLBILLPDaoImpl
  • PSPMPOLDaoImpl
  • PSPMRDRDaoImpl
  • PSPTAUDDaoImpl
  • PDFCNTRLPDaoImpl

For files of other databases such as DB2, MSSQL, MySQL, etc, use the name assigned to those files. If the name is unacceptably long, then use a surrogate name for the name of the DAO implementation class.

Written by admin

October 10th, 2014 at 6:56 am

Leave a Reply

You must be logged in to post a comment.