MichelReap
MichelReap

Reputation: 5770

Orika polymorphic mapping

I have the following entities:

public class Activity 
{
   private Long activityId;
   private String name;
   private Long year;

}


public class Course extends Activity 
{
    private Long duration;
    private Date startDate;
    private Date endDate;
    ....
}

public class Conference extends Activity
{
   private Date dueDate;
   private Person speaker;
   ....
} 

I have modeled this in my database as one Activity table with all attrbitues for child entities, and then mapped them on Hibernate using single-table strategy.

I want to retrieve all Activities for a given year. I know how to do that on the data access layer through Hibernate, my problem comes with mapping those polymorphic objects (some of them are courses and some of them are conferences) using Orika mapper: I always end up with Activity objects without each concrete entity's attributes.

More specifically, I've got a fourth class, let's call it A, which has a list of Activity elements which may be of Course or Conference class, and I would like to map it like this:

ADTO adto = map(A, ADTO.class);

I haven't found any info on this issue on the internet...

Upvotes: 3

Views: 1257

Answers (1)

Sidi
Sidi

Reputation: 1739

Orika support polymorphic mapping and within collection also

Please take a look at this PolicyElementsTestCase

There is lot of use cases within test code of Orika, you can refer to that. Hope this can help you.

Upvotes: 2

Related Questions