-->
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.  [ 7 posts ] 
Author Message
 Post subject: mapping to a Map inside an object
PostPosted: Tue Apr 20, 2004 10:11 am 
Newbie

Joined: Tue Apr 20, 2004 10:05 am
Posts: 3
Very new to hibernate and interested in using it. Does hibernate support mapping an object where the data is not stored in individual fields but rather are stored in a Map.

As an example, consider the class Foo

public class Foo {

private Map _map = new Hashtable();

public Serializable getValue(Object key) {
return (Serializable)_map.get(key);
}

public void setValue(Object key, Serializable value) {
_map.put(key,value);
}
}

Foo is then mapped to a table in the database and the columns in the database need to get mapped to keys within the Map.

Is this possible? If so, can you show me where this is covered?

Regards

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 12:52 pm 
Newbie

Joined: Tue Oct 21, 2003 6:14 pm
Posts: 11
Yes. It is possible. Check the section on Dynamic Components.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 1:14 pm 
Newbie

Joined: Tue Apr 20, 2004 10:05 am
Posts: 3
crkrishna29

I checked out Dynamic Components. There isn't a lot said in the documentation that I can tell. Before I rack my brain, it appears based upon what I saw that the keys in the map are Strings? Is this true? How would I specify some other object?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 2:04 pm 
Newbie

Joined: Tue Apr 20, 2004 10:05 am
Posts: 3
Never mind. After skimming through documentation, it looks like the answer to most questions I could possibly ask at this point is...yes. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 9:41 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Yes you can store a Map, but the value cannot be a list of objects, it has to be a single object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 5:20 pm 
Beginner
Beginner

Joined: Mon Oct 03, 2005 5:13 pm
Posts: 30
Hello everybody, I´m trying to complete a task using some of it. I´ve two classes: Emp and Func.

in Emp.hbm.xml:

Code:
...
<map name="funcs" table="func_emp" lazy="true">
  <key column="emp" />
  <composite-index class="pack.Emp">
    <key-many-to-one name="funcionario"
   class="ime.sodc.model.desastre.Funcionario" />
  </composite-index>
  <composite-element class="pack.Func">
  </composite-element>
</map>
...


My Emp.java has something like this:

Code:
private Map funcs = new Hashtable();
   
private Func func;


When I perform a test using this, I´ve to do:

Code:
Emp emp = (Emp)aSession.load(Emp.class, idEmp);
Func func = (Func)aSession.load(Func.class,idFunc);
         
emp.setFunc(func);
emp.getFuncs().put(emp,func);


I don´t want to set the func in emp, I don´t know how to resolve it. Can anyone help?

Thanks for all.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 5:25 pm 
Beginner
Beginner

Joined: Mon Oct 03, 2005 5:13 pm
Posts: 30
bonoddr wrote:
Hello everybody, I´m trying to complete a task using some of it. I´ve two classes: Emp and Func.

in Emp.hbm.xml:

Code:
...
<map name="funcs" table="func_emp" lazy="true">
  <key column="emp" />
  <composite-index class="pack.Emp">
    <key-many-to-one name="func"
   class="pack.Func" />
  </composite-index>
  <composite-element class="pack.Func">
  </composite-element>
</map>
...


My Emp.java has something like this:

Code:
private Map funcs = new Hashtable();
   
private Func func;


When I perform a test using this, I´ve to do:

Code:
Emp emp = (Emp)aSession.load(Emp.class, idEmp);
Func func = (Func)aSession.load(Func.class,idFunc);
         
emp.setFunc(func);
emp.getFuncs().put(emp,func);


I don´t want to set the func in emp, I don´t know how to resolve it. Can anyone help?

Thanks for all.


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