-->
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: Mapping a Map<String,Double> on DB2
PostPosted: Thu Feb 07, 2008 8:45 am 
Newbie

Joined: Thu Feb 07, 2008 8:07 am
Posts: 2
Hello there,
I was trying to map a Map<String, Double> on a Pojo using the automatic creation of tables
Code:
   @CollectionOfElements(fetch = FetchType.EAGER)
   private Map<String, Double> curs = new HashMap<String, Double>();

On DB2, the generated DDL is
Code:
create table CursBNR_curs (CursBNR_id bigint not null, element double, mapkey varchar(255), primary key (CursBNR_id, mapkey))

which of course results in an error
Quote:
DB2 SQL Error: SQLCODE=-542, SQLSTATE=42831, SQLERRMC=MAPKEY, DRIVER=4.0.100

since the nullable column "mapkey" is not allowed to participate in a primary key definition.
I'm using the hibernate version which comes with JBoss 4.2.2.GA.
My persistence.xml looks like this
Code:
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
   <persistence-unit name="otpdms" transaction-type="JTA">
      <jta-data-source>java:/icmnlsdbDS</jta-data-source>
      <properties>
         <property name="hibernate.archive.autodetection" value="class" />
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect" />
         <property name="hibernate.hbm2ddl.auto" value="create" />
         <property name="hibernate.transaction.manager_lookup_class"
            value="org.hibernate.transaction.JBossTransactionManagerLookup" />
         <property name="hibernate.transaction.factory_class"
            value="org.hibernate.transaction.JTATransactionFactory" />
         <property name="jboss.entity.manager.jndi.name" value="java:entityManager" />
         <property name="jboss.entity.manager.factory.jndi.name" value="java:entityManagerFactory" />
      </properties>
   </persistence-unit>
</persistence>


(Another issue is that the entity manager and entity manager factory do not get bound on the JNDI (I checked the JMX console), but that's another story)

Does anybody have the time and will to help me with that?
Thanx,
Eduard


Top
 Profile  
 
 Post subject: Finally worked
PostPosted: Thu Feb 07, 2008 10:12 am 
Newbie

Joined: Thu Feb 07, 2008 8:07 am
Posts: 2
Hi there,
somehow I managed to make it work, by using the following declaration:
Code:
   @CollectionOfElements
   @Column(name="curs", nullable=false)
   @MapKey(columns=@Column(name="moneda", nullable=false))
   private Map<String, Double> curs = new HashMap<String, Double>();

But for some reason, this works only if I use it when declaring the field; if I move it to the getter, I get some stupid exception saying something like "could not determine type for Column(curs)".

Eduard


Top
 Profile  
 
 Post subject: hibernate 2nd level cache issue
PostPosted: Thu Feb 07, 2008 6:54 pm 
Newbie

Joined: Thu Jan 31, 2008 1:48 pm
Posts: 11
it returns the query result from the cache the 2nd time but it seem to be clearing the cache. It issues the db call the 3rd time and again caches the result so the 4th time it would return the result from the cache. So it returns the result from the cache alternate time. Does anybody know what am I missing here? I have the query cache enabled in hibernate configuration file and the object's hibernate mapping file.

Here is my code....I would appreciate any help on this. Thanks in advance!


public List findAllCached() throws DataAccessException {
List dObjList = new ArrayList();
String query = "from " + domainObjectClass.getName();
try {
if (getSession() != null) {
Query qryObj = getSession().createQuery(query).setCacheable(true);
if (qryObj != null)
dObjList = qryObj.list();
}
}
catch (HibernateException e) {
logger.error(ExceptionUtils.getStackTrace(e));
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
return dObjList;
}


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.