ronan_40060
asked on
Hibernate Inheritance Strategy for Abstract Base class and two concrete classes
Friends
In order to capture the logging information of my application to the tables , I am designing three tables as shown in the attached picture.
LogType ( Table is the Static Table ) which has only two columns and two rows fixed Id = 1 , 2 and Type = Info , Debug
INFOLOG( Table ) and DEBUGLOG Tables will have additional respective information .
My Question is which Inheritance Strategy is best suited for such scenario , I think of Table for Subclass since My super table(Log Type) is constant and wont change . Please put comments with some annotation examples .
My abstract Base class looks like below
However I also think that since my base abstract class has only two static values for column LogTypeName i.e Info and Debug
I can get rid of above abstract base class by introducing enum instead of base class as shown below
Which can represent a column name in my two concrete tables as
However my questions are
1. Should I go for a abstract base class for my LogType and then use Single table per subclass
2. Should I go for a enum instead of abstract base class as shown above and then just dont use any Inheritance .
Please suggest with examples
In order to capture the logging information of my application to the tables , I am designing three tables as shown in the attached picture.
LogType ( Table is the Static Table ) which has only two columns and two rows fixed Id = 1 , 2 and Type = Info , Debug
INFOLOG( Table ) and DEBUGLOG Tables will have additional respective information .
My Question is which Inheritance Strategy is best suited for such scenario , I think of Table for Subclass since My super table(Log Type) is constant and wont change . Please put comments with some annotation examples .
My abstract Base class looks like below
@Inheritance(strategy=InheritanceType.JOINED)
@MappedSuperclass
public abstract class LogType implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "LogTypeId", nullable = false, updatable = false)
private Integer logTypeId;
@Column(name = "LogTypeName", unique = true, nullable = false, length = 10)
private String logTypeName;
}
However I also think that since my base abstract class has only two static values for column LogTypeName i.e Info and Debug
I can get rid of above abstract base class by introducing enum instead of base class as shown below
public enum LogType{
INFO,
DEBUG;
}
Which can represent a column name in my two concrete tables as
@Entity
public class InfoLog implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "InfoLogId", nullable = false, updatable = false)
private Integer infoLogId;
@Enumerated(EnumType.STRING)
@Column(name="LogType")
private LogType logType;
@Column(name = "LogDesc", nullable = false, updatable = false)
private String logDesc;
}
@Entity
public class DebugLog implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "DebugLogId", nullable = false, updatable = false)
private Integer infoLogId;
@Enumerated(EnumType.STRING)
@Column(name="LogType")
private LogType logType;
@Column(name = "DebugDesc", nullable = false, updatable = false)
private String debugLogDesc;
}
However my questions are
1. Should I go for a abstract base class for my LogType and then use Single table per subclass
2. Should I go for a enum instead of abstract base class as shown above and then just dont use any Inheritance .
Please suggest with examples
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
ASKER
I will post a new question later today . Thank you for your time and comment.