Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading data from a table in a Map as Column Name Vs Value using Hibernate
    text
    copied!<p>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.</p> <p>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.</p> <p>I am using Hibernate 4.1.4 and using Annotations to map Fields with Columns.</p> <p>As further clarification: Table Definition :</p> <pre><code>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 } </code></pre> <p>The DAO Model would look something like</p> <pre><code>@Entity @Table(name = "TempTable") public class StatsModel { private Long entryId; private String revId; private Integer type; private Integer group; private Map&lt;String, Integer&gt; 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; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload