How to represent a Set and Map Java Objects in datasets

Hello @Moses_Mutesasira, @Agaba_Derrick_Junior, @mherman22
I have been writing tests for the testcalculated services
And this ResultCalculation.java entity has two columns that I’m not yet sure how to represent them in datasets
one as a Set

    @CollectionTable(name = "test_operations", joinColumns = @JoinColumn(name = "result_calculation_id", referencedColumnName = "id"))
    @Column(name = "test_id")
    private Set<Test> test;

and the other a Map

    @CollectionTable(name = "test_result_map", joinColumns = @JoinColumn(name = "result_calculation_id", referencedColumnName = "id"))
    @MapKeyColumn(name = "test_id")
    @Column(name = "result_id")
    private Map<Integer, Integer> testResultMap;

I thought of designing them like this:

        <!-- ElementCollection: Set<testId> -->
    <test_operations result_calculation_id="1" test_id="401" />
    <test_operations result_calculation_id="2" test_id="402" />

And like this:

 <!-- ElementCollection: Map<testId, resultId> -->
    <test_result_map result_calculation_id="1" test_id="401" result_id="301" />
    <test_result_map result_calculation_id="2" test_id="402" result_id="302" />

Though the compiler throws an Exceptionorg.dbunit.dataset.NoPrimaryKeyException: thus suggesting that test_operations and test_result_map must have an id column, making them look like this:

   <!-- ElementCollection: Set<testId, resultId> -->
    <test_operations id="1" result_calculation_id="1" test_id="401" />
  • Which then makes me think that we should make them Java objects (entities) and use the @JoinColumn(name = "id") annotation to map them to the ResultCalculation entity

Please, I’m requesting for your ideas here, how can I create a data set for the ResultCalculation table?

@ Ariho-Seth
Don’t convert them into full entities unless you’re running into limitations beyond dataset generation.
Use your original modeling and XML representation — it’s semantically correct.

Please @Agaba_Derrick_Junior, may you help me visualise one entry that compiles successfully, because I tried different options, and most of them were generating Exceptions.
Thanks

@Ariho-Seth Have you taken a look at the coresponding liquibase scripts ?
It should give you an idea of how those objects should be represented in the DB/dataset

Thanks, @Moses_Mutesasira this has helped. Please check out my draft here for review and any suggested adjustments

1 Like