I'm trying to simulate 'views' of a single table (row) with several different objects, but am unclear on the possibility and implications of doing so.
Here is an example:
Code:
@Entity
@Table(name="device")
public class DeviceBase
{
@Id
@Column(name="device_id")
private int deviceId;
@Column(name="ip_address")
private String ipAddress;
// more attributes...
}
@Entity
@Table(name="device")
public class DeviceStatus
{
@Id
@Column(name="device_id")
private int deviceId;
@Column(name="status")
private int status;
}
@Entity
@Table(name="device")
public class DeviceInfo
{
@Id
@Column(name="device_id")
private int deviceId;
@Column(name="ipAddress")
private String ipAddress;
@Column(name="vendor")
private String vendor;
@Column(name="model")
private String model;
}
Several things to note are, 1) the common "deviceId" across all three classes, and 2) the visibility of "ipAddress" from both DeviceBase and DeviceInfo.
First, will Hibernate allow me to do this? Next, if so are there implications for cache coherency if updates are performed through these different objects? For example, if I use the DeviceBase object above to update the ipAddress attribute, will queries for a DeviceInfo object with the same deviceId (they are the same row) receive a possibly stale object due to caching? Is caching my only concern?
Inheritance doesn't make sense in this case because they are not separate kinds of objects (i.e. a discriminator would interfere with seeing the same row through different classes). For performance reasons we would like to avoid using separate tables and joins, hence our consideration of this approach.
Any help/insight is appreciated.
Thanks,
Brett