Skip to content

soosmarci/compare-jpa-entities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔍 Compare JPA Indexes & JoinColumns

A lightweight Python tool that compares JPA entity annotations between two folders (archive/ and actual/).

It detects differences in:

  • @Index(columnList = "...")
  • @JoinColumn(name = "...") (and inside @JoinColumns({...}))

and produces a console report, plus CSV and JSON summary files.


🚀 Features

✅ Compares entities file-by-file (.java)
✅ Ignores:

  • Index names
  • Index order ✅ Optional: ignore column order inside a single index
    ✅ Detects deleted/new join columns
    ✅ Outputs:
  • Human-readable console log
  • jpa_index_join_diff.json
  • jpa_index_join_diff.csv

🗂 Example

archive/CompanyLoan.java

@Table(name = "COMPANY_LOANS", indexes = {
    @Index(name = "CL_KHR_LOANS_FK_IDX", columnList = "KHR_LOANS_FK"),
    @Index(name = "CL_TABLE_FK_IDX", columnList = "TABLE_FK")
})
public class CompanyLoan {
    @ManyToOne
    @JoinColumn(name = "KHR_LOANS_FK")
    private KhrLoan khrLoansFk;
}

actual/CompanyLoan.java

@Table(name = "COMPANY_LOANS", indexes = {
    @Index(name = "CL_TABLE_FK_IDX", columnList = "TABLE_FK"),
    @Index(name = "CL_LOAN_FK_IDX", columnList = "LOAN_FK")
})
public class CompanyLoan {
    @ManyToOne
    @JoinColumn(name = "LOAN_FK")
    private LOAN LOANFk;
}

Output:

• CompanyLoan.java
   ❌ Missing indexes in ACTUAL (present in ARCHIVE):
      - (KHR_LOANS_FK)
   ❌ New indexes in ACTUAL (not in ARCHIVE):
      + (LOAN_FK)
   ❌ Deleted joinColumns in ACTUAL (present before):
      - KHR_LOANS_FK
   ❌ New joinColumns in ACTUAL:
      + LOAN_FK

⚙️ Usage

1️⃣ Install dependencies

Only uses Python standard libraries — no external install required.
(Optionally create a venv.)

python -m venv .venv
source .venv/bin/activate   # Linux/Mac
# or
.venv\Scripts\activate      # Windows

2️⃣ Run the tool

python compare_jpa_indexes_and_joins.py --archive ./archive --actual ./actual

Optional flags:

  • --ignore-column-order → ignores column order inside each index
  • --out-prefix → custom output name (default: jpa_index_join_diff)

Example:

python compare_jpa_indexes_and_joins.py   --archive ./archive   --actual ./actual   --ignore-column-order   --out-prefix result

🧩 Output files

File Description
jpa_index_join_diff.json Structured JSON summary
jpa_index_join_diff.csv CSV-friendly diff table
console log readable summary for human inspection

🧰 Requirements

  • Python 3.8+
  • Works on Linux, macOS, and Windows

🧪 Development & contribution

  1. Fork the repo
  2. Create a feature branch
  3. Commit changes and run the tool locally
  4. Submit a Pull Request 🎉

📜 License

MIT License — see LICENSE


🧾 Author

Developed by ChatGPT vibecoding - instructed by Márton Soós
Inspired by real-world JPA entity maintenance workflows.

About

compare entities in two folders

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages