-->
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: How to use java.util.Map as Entity attribute? [Solved]
PostPosted: Wed Mar 21, 2007 5:05 pm 
Newbie

Joined: Fri Aug 18, 2006 11:54 am
Posts: 11
Hibernate version: latest (3.2.2 with EntityManager and Annotations 3.3.0), JBoss 4.0.5, EJB3_RC9_Patch1 (I've placed new hibernate jars in jboss/server/default/lib )

Source code:
@Entity
public class Sport implements Serializable {

//...
private Map<String, String> nameMap = new HashMap<String, String>();

//...
public Map<String, String> getNameMap() {
return nameMap;
}
public String getName(String lang){
return nameMap.get(lang);
}

public void setNameMap(Map<String, String> nameMap) {
this.nameMap = nameMap;
}
public void setName(String lang, String name){
nameMap.put(lang, name);
}
//...
}

Extra info:
With hibernate version included in EJB3_RC9_Patch1 there was another excepton:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Map, for columns: [org.hibernate.mapping.Column(nameMap)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
... 99 more

Full stack trace of any exception that occurs:
23:45:55,780 WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=LineModule.jar
java.lang.NoSuchMethodError: org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(Ljava/net/URL;Ljava/util/Map;Lorg/xml/sax/EntityResolver;)Ljava/util/List;
at org.jboss.ejb3.Ejb3Deployment.initializePersistenceUnits(Ejb3Deployment.java:444)
at org.jboss.ejb3.Ejb3Deployment.create(Ejb3Deployment.java:307)
at org.jboss.ejb3.Ejb3Module.createService(Ejb3Module.java:77)

-- update --
This exception was cause by incompatibility of EJB3 RC9 with Hibernate EntityManager 3.3.0 (details)


Name and version of the database you are using:
MySQL 4


Last edited by pash_ka on Thu Mar 22, 2007 11:25 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 11:21 am 
Newbie

Joined: Fri Aug 18, 2006 11:54 am
Posts: 11
I've found the source of problem: I've forgot to use @CollectionOfElements annotation.

So the correct source is:


@Entity
public class Sport implements Serializable {

//...
private Map<String, String> nameMap = new HashMap<String, String>();

//...
@CollectionOfElements
public Map<String, String> getNameMap() {
return nameMap;
}
public String getName(String lang){
return nameMap.get(lang);
}

public void setNameMap(Map<String, String> nameMap) {
this.nameMap = nameMap;
}
public void setName(String lang, String name){
nameMap.put(lang, name);
}
//...
}


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.