pmd / pmd/pmd

[java] Java Persistence API (JPA) Entity Rule: Public or Protected No-Arg Constructor

Open
#2,854 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

a:new-rule
Dominant language
Java
Stars
5.5k
Forks
1.6k
Avg merge
1d 19h
Merged PRs (30d)
54

Description

Proposed Rule Name: JPANoArgumentConstructor

Proposed Category: Bug

Description:

When a class is annotated with JPA's @Entity, there are certain requirements placed on the class. Please create a rule that requires a no-argument constructor. The constructor must have public or protected access.

Code Sample:

The following class will cause a problem at runtime because it does not have a no-argument constructor.

@Entity
class MyEntity
{
   public MyEntity(int value)
   {
      ...
   }
}

The following class is correct.

@Entity
class MyEntity
{
   protected MyEntity()
   {
      ...
   }

   public MyEntity(int value)
   {
      ...
   }
}

Possible Properties:

  • allowPackage: Hibernate allows for package protected no-argument constructors

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files, tests, or entry points are named. Start by locating the Java rule implementation and test conventions for annotation-based rules, then verify the behavior against the two constructor examples and the optional package-private setting described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.