I have been using Hibernate for a while and this time I am trying to do something uncoventional here. Not even sure of its possible.
What I want to do is to load data from a Single table, where in few of this columns will have fields defined for them for rest (almost around 20 and can increase with time) all integers, I want to load them in a Map. Such that the name of the Column become the key and and the data its value.
I am using Hibernate 4.1.4 and using Annotations to map Fields with Columns.
As further clarification: Table Definition :
CREATE TABLE TempTable
(
id SERIAL,
revId TEXT,
type INTEGER,
group INTEGER,
col_1 INTEGER,
col_2 INTEGER,
col_3 INTEGER,
col_4 INTEGER,
col_5 INTEGER,
col_6 INTEGER,
col_7 INTEGER,
col_8 INTEGER,
col_9 INTEGER
}
The DAO Model would look something like
@Entity
@Table(name = "TempTable")
public class StatsModel {
private Long entryId;
private String revId;
private Integer type;
private Integer group;
private Map<String, Integer> metrics; // Map in which I want columns col_1 to col_9 as "Column Name" Vs. "Value"
@Id
@Column(name = "id", columnDefinition = "serial")
@Generated(GenerationTime.INSERT)
public Long getEntryId() {
return entryId;
}
public void setEntryId(Long entryId) {
this.entryId = entryId;
}
@Column(name = "tx_rev")
public String getRevId() {
return revId;
}
public void setRevId(String revId) {
this.revId= revId;
}
@Column(name = "nu_type")
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
@Column(name = "nu_group")
public Integer getGroup() {
return group;
}
public void setGroup(Integer group) {
this.group = group;
}
}