Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 2.38 KB

File metadata and controls

42 lines (36 loc) · 2.38 KB

Description:

Alters the complex field example to leverage a traditional JPA OneToMany associated collection. The relates to a new table in the database, rather than serializing to JSON.

Goals:

  • Show table based complex field support in the JpaProduct extension

  • Demonstrate custom mapping to/from projection

  • Demonstrate special @ProjectionPostConvert support for setting bi-directional references

  • Show supporting admin customization

  • Builds On : 00200-productExtensionComplexFieldJson

Key Steps:

  • Create spring boot autoconfiguration class ProductExtensionComplexFieldTableBased, which will be referenced from META-INF/spring.factories

  • Create MyAutoCoProduct repository domain class extending Broadleaf’s JpaProduct

  • Create Upgrade repository domain class, which will serve as a OneToMany collection member

  • Create Characteristics repository domain class, which will serve as a OneToOne relationship

    • Use @MapsId on the OneToOne reference back to the parent entity

    • Use a non-generated @Id field with the same column as the @JoinColumn from the OneToOne backreference

    • It is important for the id to not be generated in order for sandboxing transitions to function appropriately

  • Add new OneToMany JPA collection field to MyAutoCoProduct

  • Create MyAutoCoProductProjection class extending Broadleaf’s Product

  • Implement getBusinessDomainType(..) in the domain class

  • Implement toMe(..) and fromMe(..) in the domain class

    • Call the super implementation of the method override first

    • Use MappingUtils.setupExtensions(..) to setup the extension mapping with the converter

  • Annotate method in Upgrade with @ProjectionPostConvert to handle bi-direction reference back to MyAutoCoProduct

  • Annotate method in Characteristics with @ProjectionPostConvert to handle bi-direction reference back to MyAutoCoProduct

  • Add JpaEntityScan annotation to autoconfiguration class above for new extended entity class

  • Add AutoConfigureBefore(..) annotation to autoconfiguration class above to make sure the entity reference is scanned before JPA processing