addJPAAnnotations

Description

If you activate this configuration toggle via the builder method withJPAAnnotations the generator scans the selected classes for the following JPA Annotations:

  • class annotations

    • javax.persistence.Index

    • javax.persistence.UniqueConstraint

    • javax.persistence.Entity

    • javax.persistence.Table

    • javax.persistence.MappedSuperclass

    • jakarta.persistence.Index

    • jakarta.persistence.UniqueConstraint

    • jakarta.persistence.Entity

    • jakarta.persistence.Table

    • jakarta.persistence.MappedSuperclass

  • field annotations

    • javax.persistence.Column

    • javax.persistence.Id

    • javax.persistence.Transient

    • jakarta.persistence.Column

    • jakarta.persistence.Id

    • jakarta.persistence.Transient

  • relationship annotations

    • javax.persistence.OneToOne

    • javax.persistence.OneToMany

    • javax.persistence.ManyToMany

    • javax.persistence.ManyToOne

    • jakarta.persistence.OneToOne

    • jakarta.persistence.OneToMany

    • jakarta.persistence.ManyToMany

    • jakarta.persistence.ManyToOne

If class annotations are found the generator adds a separate compartment to the head of the PlantUML class with all informations found in these annotations.

If field annotations are found the generator adds them right before the field name in the PlantUML class.

If relationship annotations are found they are added to the relationships between the different classes in the PlantUML diagram.

Default value

The default value of this configuration toggle is false.

Example

Here is an example from the JUnit tests using this configuration parameter:

List<String> scanPackages = new ArrayList<>();
scanPackages.add(packageUnderTest);
PlantUMLClassDiagramConfig config = new PlantUMLClassDiagramConfigBuilder(scanPackages).withJPAAnnotations(true)
        .build(); (1)
PlantUMLClassDiagramGenerator generator = new PlantUMLClassDiagramGenerator(config);
String result = generator.generateDiagramText();
String expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource(expectedFileName)), StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
1 activate the jpa annotations toggle in the configuration

which is rendered this way:

0021_jpa_annotations_diagram

and produces this PlantUML diagram text:

@startuml

class de.elnarion.test.domain.t0021.Address <<Entity>>  {
}


class de.elnarion.test.domain.t0021.Employee <<MappedSuperclass>>  {
	{field} +@Id empId : Integer
	{field} #version : Integer
}


class de.elnarion.test.domain.t0021.FTEmployee <<Entity>>  <<Table>>  {
 {TableIndexes=\n\tIndex (columnList=[salaray,empId],unique=[true] )\n\tIndex (columnList=[version],unique=[false] )\n}
 {TableName=FTEmployee}
 {TableUniqueConstraints=\n\tUniqueConstraint (columnNames=[empId,version] )\n\tUniqueConstraint (columnNames=[empId] )\n}
--
	{field} +salary : Integer
}


class de.elnarion.test.domain.t0021.Family <<Entity>>  {
	{field} +description : String
	{field} +@Id id : int
}


class de.elnarion.test.domain.t0021.Job <<Entity>>  {
	{field} +@Id id : int
	{field} +jobDescr : String
	{field} +salery : double
}


class de.elnarion.test.domain.t0021.Person <<Entity>>  {
	{field} +firstName : String
	{field} +@Id id : String
	{field} +lastName : String
	{field} +@Transient nonsenseField : String
}


class de.elnarion.test.domain.t0021.Todo <<Entity>>  <<Table>>  {
 {TableName=TABLENAME}
 {TableSchema=SCHEMA}
--
	{field} +@Column("DESCR") description : String
	{field} +@Column("IDX") @Id id : Long
}


enum de.elnarion.test.domain.t0021.TodoStateEnum {
	{field} +CLOSED
	{field} +IN_PROGRESS
	{field} +OPEN
}




de.elnarion.test.domain.t0021.Employee -->  de.elnarion.test.domain.t0021.Address :  @ManyToOne\naddress
de.elnarion.test.domain.t0021.FTEmployee --|>  de.elnarion.test.domain.t0021.Employee
de.elnarion.test.domain.t0021.Family "1" o-- "0..*"  de.elnarion.test.domain.t0021.Person :  @OneToMany\nmembers
de.elnarion.test.domain.t0021.Person "1" o-- "0..*"  de.elnarion.test.domain.t0021.Job :  @OneToMany\njobList
de.elnarion.test.domain.t0021.Person -->  de.elnarion.test.domain.t0021.Family :  @ManyToOne\nfamily
de.elnarion.test.domain.t0021.Todo -->  de.elnarion.test.domain.t0021.TodoStateEnum :  @Column("STATE")\nstate


@enduml