-->
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: Can not mapping java.util.Map
PostPosted: Wed Apr 12, 2006 6:03 pm 
Newbie

Joined: Wed Apr 12, 2006 5:27 pm
Posts: 1
I can map java.util.Map in Server.java

Hibernate version:3.1.2

Mapping documents:
Code:
@Entity
@Table(name="ServerGroup")
public class Group {

   private long id;
   private String name;
   private Collection<Server> servers;

   @Id @GeneratedValue
   public long getId(){
                    return id;
   }
   
   public void setId(long id){
      this.id = id;
   }

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
   public Collection<Server> getServers() {
      return servers;
   }

   public void setServers(Collection<Server> servers) {
      this.servers = servers;
   }

}



Code:
@Entity
public class Server {

   private long id;
   private String name;
   private String address;
   private String user;
   private String password;
   private Map<String, SharedFolder> sharedFolders;

   
   
   
   @Id @GeneratedValue
   public long getId() {
      return id;
   }

   public void setId(long id) {
      this.id = id;
   }
      
                ...
                ...
                ...
   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
   @MapKey(name="letter")
   @JoinColumn(name="server_id")
   public Map<String, SharedFolder> getSharedFolders() {
      return sharedFolders;
   }
   
   public void setSharedFolders(Map<String, SharedFolder> sharedFolders) {
      this.sharedFolders = sharedFolders;
   }

}


Code:
@Entity
public class SharedFolder {
      
   private long id;
   private String relativePath;
   private String letter;
   
   @Id @GeneratedValue
   public long getId(){
      return id;
   }
   
   public void setId(long id){
      this.id = id;
   }
   
   
   public String getRelativePath(){
      return relativePath;
   }
   
   public void setRelativePath(String path){
      this.relativePath = path;
   }
   
   ...
}



Code between sessionFactory.openSession() and session.close():

Code:
Insert some values
Session se = HibernateUtil.getSessionFactory().getCurrentSession();
      se.beginTransaction();
      
      Group g = new Group();
      g.setName("Group 1");
      
      LinkedList<Server> list = new LinkedList<Server>();
      g.setServers(list);
      
      for (int i=0; i<10; i++){
         Server s = new Server();
         s.setName("Server "+i);
         
         TreeMap<String, SharedFolder> map = new TreeMap<String, SharedFolder>();
         s.setSharedFolders(map);
         
         for (int k=0; k<10; k++){
            SharedFolder folder = new SharedFolder();
            folder.setRelativePath("\\share"+k);
            s.getSharedFolders().put(" "+k,folder);
         }
         g.getServers().add(s);
      }
            
      se.save(g);
      se.getTransaction().commit();


Read some values

Session s = HibernateUtil.getSessionFactory().getCurrentSession();
      s.beginTransaction();
      
        List result = s.createQuery("from Group").list();
        Group g = (Group)result.get(0);
      
      
         logger.debug("Servers> "+ g.getServers().size());
Server server = g.getServers().iterator().next();
         logger.debug(server.getName()+" SharedFolders>"+server.getSharedFolders().size());
   }
      rootNode.add(serverNode);
   }
s.getTransaction().commit();


Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.HibernateException: null index column for collection: sk.netmap.bo.Server.sharedFolders
at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:652)
at org.hibernate.collection.PersistentMap.readFrom(PersistentMap.java:222)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:994)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1695)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
at org.hibernate.collection.PersistentMap.size(PersistentMap.java:95)
at sk.netmap.gui.TreeModel.createTree(TreeModel.java:43)
at sk.netmap.gui.MainFrame.buildMainPanel(MainFrame.java:381)
at sk.netmap.gui.MainFrame.buildContentPane(MainFrame.java:331)
at sk.netmap.gui.MainFrame.buildInterface(MainFrame.java:227)
at sk.netmap.gui.MainFrame.main(MainFrame.java:175)
Name and version of the database you are using:
HSQLDB 1.8.0


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 8:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
there is no letter property in ShareFolder apparently

_________________
Emmanuel


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.