-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Exotic mapping (value type with internal Hashmap)
PostPosted: Wed May 27, 2009 3:53 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 4:10 pm
Posts: 38
Location: Charleston, SC
I'm not really sure how to map the following case with the latest hibernate. I have two objects: a Table class and a TableRow class. I included the basic definition of each one. Table is an entity and TableRow is a value type. The complexity comes from TableRow using a Map to store the column names and values. We want to map each column name and value in TableRow to TABLE_DATA. The column names are the hashmap keys. We have two tables in our database right now: DOC_TABLE and a second, TABLE_DATA, with a foreign key to the DOC_TABLE primary key. Any suggestions? I couldn't find a good example in the documentation that covers this specific case. Thanks.

Code:
DOC_TABLE columns:
TABLE_ID
NAME
DESCRIPTION
CAPTION

TABLE_DATA columns:
TABLE_ID (FK)
COL_NAME
COL_DATA
ROW_INDEX


Code:
public class Table implements PersistentEntity {
    private Integer tableId;

    private String name;

    private String description;

    private String caption;

    private List<TableRow> tableRows = new ArrayList<TableRow>();

    public Integer getId() {
        return tableId;
    }

    private void setId(Integer id) {
        this.tableId = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCaption() {
        return caption;
    }

    public void setCaption(String caption) {
        this.caption = caption;
    }

    public void addRow(TableRow row) {
    }

    public List getRows() {
        return null;
    }

    public void setRows(List tableRows) {

    }
}

public class TableRow {
    private Map<String, String> rowData;

    public TableRow() {
    }

    public String getColumnValue(String columnName) {
        return null;
    }

    public void setColumnValue(String columnName, String columnValue) {
    }

    public Map getRowData() {
        return null;
    }

    public void setRowData(Map rowData) {

    }
}


Top
 Profile  
 
 Post subject: Re: Exotic mapping (value type with internal Hashmap)
PostPosted: Wed May 27, 2009 8:27 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 4:10 pm
Posts: 38
Location: Charleston, SC
This is what I came up before I got stuck. I don't see any way to map the HashMap in the TableRow component class using the Hibernate DTD. If Hibernate supports this mapping I can't figure out how without modifying the database and making TableRow an entity instead of a value class dependent on the Table entity class.

Code:
<hibernate-mapping package="...">
    <class name="Table" table="HITSP_DOC_TABLE">
        <id name="id" column="TABLE_ID" type="integer">
            <generator class="native"/>
        </id>

        <property name="name" column="NAME"/>
        <property name="description" column="DESCRIPTION"/>
        <property name="caption" column="CAPTION"/>

        <list name="rows" table="HITSP_TABLE_DATA">
            <key column="TABLE_ID"/>
            <list-index column="ROW_INDEX"/>
            <composite-element class="TableRow">
                 ?...
            </composite-element>

        </list>
    </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.