-->
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: Removing @MapKey causes MappingException? Why?
PostPosted: Tue May 25, 2010 8:46 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi, I have just ugraded from Hibernate 3.4 to 3.5.2.
Now @MapKey and @MapKeyManyToMany are deprecated.

But when I remove them as suggested, cause Hibernate should now be aware of generics. I receive a MappingException:
Quote:
org.hibernate.MappingException: collection index mapping has wrong number of columns: de.zew.vitax.tax.taxbase.shareholderAssetAndIncome.TaxBaseShareholderAssetOrIncome.map type: object


Code:

@Entity
@DiscriminatorValue(value = "Node")
public class TB_NodeData<K extends Enum<K>, V extends TB_BasicData> extends TB_BasicData {

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, targetEntity = TB_BasicData.class, orphanRemoval = true)
    @MapKeyManyToMany(targetEntity = Enum.class)
    @Fetch(value = FetchMode.SELECT)
    private Map<K, V> subMap;


Quote:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "AssetOrIncome", discriminatorType = DiscriminatorType.STRING)
public abstract class TaxBaseShareholderAssetOrIncome<K extends Enum<K>> extends TaxBaseImp {
...
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, targetEntity = TB_LeafDataShareholder.class, orphanRemoval = true)
@org.hibernate.annotations.MapKey(targetElement = Enum.class)
protected Map<K, TB_LeafDataShareholder> map;


What's wrong and how can I fix without deprecated annotations?
Sure MapKeyColumn and MapKeyJoinColumn should replace them, but I don't know how. Especially cause there is no "target" attribute any more.

Before the upgrade it worked fine and resulted in the intended schema.
Thanks.

Greetings Michael


Top
 Profile  
 
 Post subject: Re: Removing @MapKey causes MappingException? Why?
PostPosted: Wed Aug 04, 2010 11:25 pm 
Newbie

Joined: Wed Aug 04, 2010 11:09 pm
Posts: 1
Maybe @MapKeyClass?


Top
 Profile  
 
 Post subject: Re: Removing @MapKey causes MappingException? Why?
PostPosted: Thu Aug 05, 2010 10:15 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Thanks, that's removing the mapping exception, but raises a PSQLException.
Code:
org.postgresql.util.PSQLException: ERROR: column map0_.map_key does not exist


See below for full listing.

May be I have to recreate the whole db-schema to get rid of this?

Thanks.

Greetings Michael

Code:
ERROR de.zew.vitax.database.TransactionManager  - could not initialize a collection batch: [de.zew.vitax.tax.taxbase.shareholderAssetAndIncome.TaxBaseShareholderAssetOrIncome.map#<69042, 68830, 68942, 68925, 68844, 68802, 68879, 68961, 69010, 68814>]
org.hibernate.exception.SQLGrammarException: could not initialize a collection batch: [de.zew.vitax.tax.taxbase.shareholderAssetAndIncome.TaxBaseShareholderAssetOrIncome.map#<69042, 68830, 68942, 68925, 68844, 68802, 68879, 68961, 69010, 68814>]
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.loader.Loader.loadCollectionBatch(Loader.java:2107)
   at org.hibernate.loader.collection.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:81)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:628)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1853)
   at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:476)
   at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:899)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:275)
   at org.hibernate.loader.Loader.doList(Loader.java:2294)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
   at org.hibernate.loader.Loader.list(Loader.java:2167)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:859)
   at de.zew.vitax.database.TransactionManager.getCountryByID(TransactionManager.java:526)
   at de.zew.vitax.database.TransactionManager.getCountriesByID(TransactionManager.java:496)
   at de.zew.vitax.gui.main.menu.db.SelectCountriesFromDB.showLoadDialog(SelectCountriesFromDB.java:134)
   at de.zew.vitax.gui.main.menu.sim.CountryMenu$6$1.run(CountryMenu.java:520)
Caused by: org.postgresql.util.PSQLException: ERROR: column map0_.map_key does not exist
  Position: 94
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1849)
   at org.hibernate.loader.Loader.doQuery(Loader.java:718)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
   at org.hibernate.loader.Loader.loadCollectionBatch(Loader.java:2100)


Top
 Profile  
 
 Post subject: Re: Removing @MapKey causes MappingException? Why?
PostPosted: Thu Aug 19, 2010 1:32 pm 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Yeah, had to rebuild the database schema.
Now it works.

Thanks.

Greetings Michael


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.