Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

JPA2DataSource child relationship abstraction

$
0
0
Let me start by showing you the entity model:

1. VideoStream.java
Code:

@Entity
@Inheritance(strategy = InheritedType.Joined)
@DiscriminatorColumn(name = "discriminator")
public abstract class VideoStream {
  @Id
  private long id;

  @Column(insertable = false, updatable = false)
  private String discriminator;

  //more fields, etc
}

VideoStreamGenerated.java
Code:

@MappedSuperclass
public abstract class VideoStreamGenerated extends VideoStream {
 //some fields etc
}

VideoStreamLive.java
Code:

@Entity
@DiscriminatorValue(value = "Live")
public class VideoStreamLive extends VideoStreamGenerated {
  @OneToMany(mappedBy = "videoStream", cascade = { CascadeType.DETACH, CascadeType.REFRESH,  CascadeType.REMOVE }, fetch = FetchType.EAGER)
        private List<VideoStreamDestination> destinations = new ArrayList<>();

  //more fields
}

VideoStreamArchived.java
Code:

@Entity
@DiscriminatorValue(value = "Archived")
public class VideoStreamArchived extends VideoStreamGenerated {
  @OneToOne(mappedBy = "videoStream", cascade = { CascadeType.DETACH, CascadeType.REFRESH, CascadeType.REMOVE }, fetch = FetchType.EAGER)
        private VideoStreamDestination destination = new VideoStreamDestination();

  //more fields
}

VideoStreamDestination.java
Code:

@Entity
public class VideoStreamDestination {
  @ManyToOne
  @JoinColumn(updatable = false)
  private VideoStream videoStream;
}

VideoStream_JPA.ds.xml
Code:

<DataSource
        allowAdvancedCriteria="true"
        dropExtraFields="false"
        beanClassName="com.sncorp.gs2.jee.entities.VideoStream"
        ID="VideoStream_JPA"
        serverConstructor="com.sncorp.gs2.gsui.server.datasource.FetchOnlyJPA2DataSource"
        >
    <fields>
        <field name="id" primaryKey="true" type="sequence"/>
        <field name="discriminator" type="text"/>
        <field name="name" type="text"/>
        <field name="owner" type="text"/>
        <field name="description" required="false" type="text"/>
    </fields>
</DataSource>

VideoStreamGenerated_JPA.ds.xml
Code:

<DataSource
        allowAdvancedCriteria="true"
        dropExtraFields="false"
        beanClassName="com.sncorp.gs2.jee.entities.VideoStreamGenerated"
        ID="VideoStreamGenerated_JPA"
        inheritsFrom="VideoStream_JPA"
        >
    <fields>
        <!-- some fields -->
    </fields>
</DataSource>

VideoStreamLive_JPA.ds.xml
Code:

<DataSource
        allowAdvancedCriteria="true"
        dropExtraFields="true"
        beanClassName="com.sncorp.gs2.jee.entities.VideoStreamLive"
        ID="VideoStreamLive_JPA"
        serverConstructor="com.sncorp.gs2.gsui.server.datasource.FetchOnlyJPA2DataSource"
        inheritsFrom="VideoStreamGenerated_JPA"
        >
        <fields>
        <!-- some fields -->
        </fields>
</DataSource>

VideoStreamDestination_JPA.ds.xml
Code:

<DataSource
        allowAdvancedCriteria="true"
        dropExtraFields="false"
        beanClassName="com.sncorp.gs2.jee.entities.VideoStreamDestination"
        ID="VideoStreamDestination_JPA"
        serverConstructor="com.sncorp.gs2.gsui.server.datasource.FetchOnlyJPA2DataSource"
        >
    <fields>
        <!-- some fields -->
        <field name="videoStream" type="VideoStream_JPA"/>
    </fields>   
</DataSource>

Given this setup, I can fetch against VideoStream_JPA.ds.xml and the results will actually contain all of the values from the concrete VideoStream implementation. Which is highly desirable. However, when I fetch from VideoStreamDestination_JPA.ds.xml the child stream only contains the fields specifically declared in VideoStream_JPA.ds.xml and not the fields from the concrete VideoStream implementation.
Is there a mechanism where I can easily have it return the actual concrete classes fields in the child entity? In our use case, there are actually 3 concrete implementations of VideoStream.java, and I would like to be able to return all destinations that belong to a user in a single fetch, but I need the concrete VideoStream class to work with on the client.

Your help is greatly appreciated.

Viewing all articles
Browse latest Browse all 4756

Trending Articles