-->
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.  [ 3 posts ] 
Author Message
 Post subject: HashMap Mapping help
PostPosted: Thu Oct 09, 2003 1:29 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

I'm having some problems in storing a Java HashMap.


<map name="hashMap" table="TextHashMap">
<key column="chvp"/>
<index column="idioma" type="string"/>
<element column="text" type="string"/>
</map>


What is the meaning of key, index and element? When i try to store the object i get a class cast exception to set the Property values os the element.

Thanks in advance,
Joao Rangel


java.lang.ClassCastException

at tipos.TipoDeContentorMetaClass4.setPropertyValues(<generated>)

at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:162)

at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:709)

at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)

at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1202)


Top
 Profile  
 
 Post subject: Another HashMapProblem
PostPosted: Thu Oct 09, 2003 1:48 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

I forgot to mention another problem related with the previous post.

And if the HashMap is inside an object, which is a field of the persistent class? How can i store that HashMap in an assossiation table?


public class Objecto
{
private HashMap dataText = null;

...


public class StorableClass
{
private Integer chvp;
private String codigo;
private Objecto descricao;...


Thanks again,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 3:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The key, as for all collection mappings, is the column in the association table which identifies the map owner.

The index represent the column in the association table to be used as the index or key of the Map.

The element represents the column in the association table to be used as the element or value of the Map for the given index.

Quote:
And if the HashMap is inside an object

The map must be owned by a persistent class, so this question does not really make sense. Maybe I misunderstood what your asking?

As an example, say you have a class named Book and part of the Book class is a localized assoication to the contents of the book. The class looks something like:
Code:
public class Book
{
    private Long id;
    java.util.Map localizedContent = new java.util.HashMap();
    ...
    // Getters and setters...
}


And you want to map this content to an association table:
BOOK_CONTENT
----------------------------
BOOK_ID INTEGER
LOCALE VARCHAR(5)
CONTENT_LOCATION VARCHAR(4000)

That would look like:
Code:
<class name="Book" table="... >
    ...
    <map name="localizedContent" table="book_content">
        <key column="book_id"/>
        <index column="locale"/>
        <element column="content_location"/>
    </map>
</class>


After loading an instance of Book, the getLocalizedContent() method would return a Map of the book's content keyed by the locale for that particular content.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.