I’m seeking an alternative to the deprecated <dynamic-component />
for my plugin-based application architecture. My app can be deployed with different configurations/plugins that remain static during runtime. Let’s say, taht I have a base Person
entity with a plugins
map that should dynamically contain related entities like PersonAddress
and PersonContactInfo
.
I successfully implemented this using <dynamic-component />
in XML mapping, where I defined one-to-one relationships within the component. This works well for both loading and saving entities, but since <dynamic-component />
is deprecated, I need a modern alternative.
I’m considering using TypeBinder
or AdditionalMappingContributor
to manually extend the plugins
property, but I’m concerned about the amount of manual work required, potential future deprecation (since I need to use the dynamic
property for this to work), and added complexity when adding nested component mappings.
Has anyone implemented a similar plugin architecture with the annotation APIs that allows dynamic population of a map during entity loading and proper persistence during save operations? I need a solution that supports both one-to-one relationships and potentially nested components.
Any guidance would be appreciated.
Example code (where the application could be deployed with a module containing the Person
class, and any combination of PersonAddress
and PersonContactInfo
):
public class Person {
private Long id;
private String firstName;
private String lastName;
private Map<String, Object> plugins; // Needs to be populated dynamically
// ... getters, setters, constructors
}
@Entity
@Table(name = "person_address")
public class PersonAddress {
@Id
@Column(name = "person_id")
private Long id;
@OneToOne
@MapsId
@JoinColumn(name = "person_id")
private Person person;
// Address fields...
}
// Similar structure for PersonContactInfo, ...
Mapping, that is generated during the startup of the application:
<!-- Other mapping of the Person component -->
<dynamic-component name="plugins">
<one-to-one name="personAddress" class="org.example.PersonAddress" cascade="all" />
<one-to-one name="personContactInfo" class="org.example.PersonContactInfo" cascade="all" />
</dynamic-component>