views:

80

answers:

1

In Java I have a class tha has a payload of type T

public class GenericStatus<T> {
   private MyDateRange myDateRange;  
   private T payload;

At runtime T can be either a simple primitive Integer or a class called Price where Price is a class with 2 integers

public class Price implements Serializable {
   private int adult;
   private int child;

How can you deal with loading / saving of the class GenericStatusElement ? I have 2 classes that are using this

public class MasterPrice implements Serializable {
    // this.basePrice is an instance of Price class
    private GenericStaus prices = new GenericStatus(this.basePrice); 

and

public class MasterStatus implements Serializable {
    // roomcount is an int
    GenericStaus availStatus = new GenericStatus(roomCount); 

I keep scratching my head but I still cannot find a proper way to deal with GenericStatus from Hibernate point of view.

I would like to be able to save the MasterPrice and MasterStatus classes. GenericStatus class is used to reduce the duplicate code that MasterStatus and MasterPrice would have. Shall I look to implement the relationship with inheritance ? will it make easier to fix ?

A: 

I keep scratching my head but I still cannot find a proper way to deal with GenericStatus from Hibernate point of view.

The answer is simple: generic entities can not be mapped.

Shall I look to implement the relationship with inheritance ? will it make easier to fix ?

That's what I'd do.

Pascal Thivent