-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to map a Map with Hibernate/Java5 annotations ?
PostPosted: Tue Oct 04, 2005 10:33 am 
Newbie

Joined: Tue Oct 04, 2005 10:03 am
Posts: 1
I try to migrate xdoclet annotations to Java5 annotations.
Does someone know how to map a java.util.Map in Hibernate/Java 5 annotations ?

Xdoclet :
Code:
/**
* @hibernate.map table="i18n_category"
* @hibernate.collection-key column="category_id"
* @hibernate.collection-index column="language" type="java.lang.String" length="2"
* @hibernate.collection-composite-element class="net.itcmedia.decomatic.bo.I18NCategory"
*/
public Map getI18nMap() {
    return i18nMap;
}


Java5 :
Code:
@MapKey(name="category_id")
@JoinTable(
    table=@Table(name="i18n_category"),
    joinColumns=@JoinColumn(name="category_id")
)
@IndexColumn(name="language")
@Type(type="net.itcmedia.decomatic.bo.I18NCategory")
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public Map<String,I18NCategory> getI18nMap() {
    return i18nMap;
}


Full stack trace of exception that occurs:
Code:
Hibernate: select this_.id as id0_, this_.d_cre as d2_0_0_, this_.d_del as d3_0_0_, this_.d_upd as d4_0_0_, this_.i18nMap as i5_0_0_ from category this_ where this_.d_del is null
Oct 4, 2005 4:19:22 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1054, SQLState: S0022
Oct 4, 2005 4:19:22 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Column not found,  message from server: "Unknown column 'this_.i18nMap' in 'field list'"
Oct 4, 2005 4:19:22 PM org.springframework.web.servlet.FrameworkServlet processRequest
SEVERE: Could not complete request
net.itcmedia.decomatic.service.ServiceException: net.itcmedia.decomatic.dao.DAOException: org.hibernate.exception.SQLGrammarException: could not execute query


Hibernate version: 3.0.5
Hibernate annotations version: 3.1beta4

Thanks
Gilles


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 11:41 am 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
AFAIK, Java 5 annotations only maps to POJOs. (This makes sense because you can't annotate the Map class.)

This leaves you with two choices: keep using an *.hbm.xml file for your Map entities (it's possible to mix and match annotations and hbm files) OR, you can create a POJO, annotate it, but retrieve the entity as a Map object using getSession (EntityMode.MAP).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 05, 2005 9:22 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Map having a index element is currently not implemented. On the roadmap though

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 05, 2005 9:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
patrick_ibg wrote:
AFAIK, Java 5 annotations only maps to POJOs. (This makes sense because you can't annotate the Map class.)

This is wrong, you can of course map associations

_________________
Emmanuel


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