'Using a CompositeItemWriter that has JdbcBatchItemWriters to write different object types to different tables
I have a nested object like this where the datasource is the same. However, I need to write to different tables. Here is the structure of my object. Is this possible?
class Project {
ProjectItem projectItem;
ItemOwner owner;
}
@Bean
JdbcBatchItemWriter projectItemWriter(DataSource datasource){
return new JdbcBatchItemWriter<ProjectItem> {
... etc
}
@Bean
JdbcBatchItemWriter itemOwnerWriter(DataSource datasource){
return new JdbcBatchItemWriter<ItemOwner> {
... etc
}
@Bean
CompositeItemWriter<Project> txnWriter() {
return new CompositeItemWriterBuilder<Department>()
.delegates(projectItemWriter(null),
itemOwnerWriter(null))
.build();
}
My use case is unique as I need to somehow write to different tables based on the object type. Is this possible. and if so how can I achieve this?
Solution 1:[1]
Used a JPA solution instead. I needed to write all the nested items so I chose to use JPA
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BreenDeen |
