-->
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: Association map with object as a key cease to work in rc2
PostPosted: Mon Nov 07, 2005 1:06 pm 
Newbie

Joined: Thu Aug 25, 2005 3:59 am
Posts: 7
Location: Czech Republic, Prague
Greetings, I have problem with association map using object as a map key. Everything worked fine in Hibernate 3.1 beta 3. But stop working when I tried it on rc2, with org.hibernate.type.SerializationException: could not deserialize.
If I put an Integer as the map key instead of that object, everything is OK.
I searched the hibernate web for examples using objects as keys in a map, but find none.
If anyone could point me to such an example or even tell me whats wrong with my case, I would greatly appreciate it.

Hibernate version:
3.1rc2

Mapping documents:
Code:
@Entity
@Table(name="service_package"
   ,schema="public"
)
public class ServicePackageT implements java.io.Serializable {
   
   private Integer id;
   private Map<ServiceT, SpServiceT> spService;
   
   public ServicePackageT() {
   }
   
   public ServicePackageT(Integer spId) {
      this.id = spId;
   }
   
   @Id
   @Column(name = "sp_id")
   public Integer getId() {
      return this.id;
   }
   
   public void setId(Integer spId) {
      this.id = spId;
   }


   // here is the problem <<<<<<<<<<<<<<<<<
   
   @OneToMany(fetch = FetchType.EAGER)
   @JoinColumn(name = "sp_id")
   @MapKey(name="service")
   public Map<ServiceT, SpServiceT> getSpService() {
      return spService;
   }
   
   public void setSpService(Map<ServiceT, SpServiceT> spService) {
      this.spService = spService;
   }
   ...
}

@Entity
@Table(name="sp_service"
   ,schema="public"
)
public class SpServiceT  implements java.io.Serializable {
   
   private Integer id;
   private ServicePackageT sp;
   private ServiceT service;
   
   public SpServiceT() {
   }
   
   public SpServiceT(Integer spServiceId) {
      this.id = spServiceId;
   }
   
   @Id
   @Column(name = "sp_service_id")
   public Integer getId() {
      return this.id;
   }
   
   public void setId(Integer spServiceId) {
      this.id = spServiceId;
   }

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "service_id")
   public ServiceT getService() {
      return this.service;
   }
   
   public void setService(ServiceT service) {
      this.service = service;
   }

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "sp_id")
   public ServicePackageT getSp() {
      return this.sp;
   }
   
   public void setSp(ServicePackageT sp) {
      this.sp = sp;
   }
   ...
}

@Entity
@Table(name="service"
    ,schema="public"
)
public class ServiceT  implements java.io.Serializable {
   
    private Integer id;
   
    public ServiceT() {
    }
   
    public ServiceT(Integer serviceId) {
        this.id = serviceId;
    }
   
    @Id
    @Column(name = "service_id")
    public Integer getId() {
        return this.id;
    }
   
    public void setId(Integer serviceId) {
        this.id = serviceId;
    }
    ...
}


Full stack trace of any exception that occurs:
Code:
org.hibernate.type.SerializationException: could not deserialize
   at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:211)
   at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:234)
   at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:78)
   at org.hibernate.type.SerializableType.get(SerializableType.java:39)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
   at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:650)
   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:579)
   at org.hibernate.loader.Loader.doQuery(Loader.java:689)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
   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:1565)
   at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
   at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:791)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:228)
   at org.hibernate.loader.Loader.doList(Loader.java:2147)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
   at org.hibernate.loader.Loader.list(Loader.java:2021)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:296)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:992)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   ...
Caused by: java.io.StreamCorruptedException: invalid stream header
   at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
   at java.io.ObjectInputStream.<init>(Unknown Source)
   at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:246)
   at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:203)
   ...


Name and version of the database you are using:
PostgreSQL 7.4.7

The generated SQL (show_sql=true):
Hibernate: select servicepac0_.sp_id as sp1_3_ from public.service_package servicepac0_ where servicepac0_.sp_id=2450
Hibernate: select spservice0_.sp_id as sp3_2_, spservice0_.sp_service_id as sp1_2_, spservice0_.service_id as formula1_2_, spservice0_.sp_service_id as sp1_4_1_, spservice0_.service_id as service2_4_1_, spservice0_.sp_id as sp3_4_1_, servicet1_.service_id as service1_5_0_ from public.sp_service spservice0_ left outer join public.service servicet1_ on spservice0_.service_id=servicet1_.service_id where spservice0_.sp_id=?

Debug level Hibernate log excerpt:
Code:
07.11.05 17:36:12,684 DEBUG org.hibernate.impl.SessionImpl opened session at timestamp: 4634138102063104
07.11.05 17:36:12,684 DEBUG org.hibernate.transaction.JDBCTransaction begin
07.11.05 17:36:12,684 DEBUG org.hibernate.jdbc.ConnectionManager opening JDBC connection
07.11.05 17:36:12,684 DEBUG org.hibernate.connection.DriverManagerConnectionProvider total checked-out connections: 0
07.11.05 17:36:12,684 DEBUG org.hibernate.connection.DriverManagerConnectionProvider using pooled JDBC connection, pool size: 0
07.11.05 17:36:12,715 DEBUG org.hibernate.transaction.JDBCTransaction current autocommit status: false
07.11.05 17:36:12,715 DEBUG org.hibernate.jdbc.JDBCContext after transaction begin
07.11.05 17:36:12,730 DEBUG org.hibernate.impl.SessionImpl find: from ServicePackageT item where item.id = 2450
07.11.05 17:36:12,730 DEBUG org.hibernate.engine.QueryParameters named parameters: {}
07.11.05 17:36:12,949 DEBUG org.hibernate.hql.ast.QueryTranslatorImpl parse() - HQL: from cz.test.ServicePackageT item where item.id = 2450
07.11.05 17:36:12,980 DEBUG org.hibernate.hql.ast.AST --- HQL AST ---
\-[QUERY] 'query'
    +-[SELECT_FROM] 'SELECT_FROM'
    |  \-[FROM] 'from'
    |     \-[RANGE] 'RANGE'
    |        +-[DOT] '.'
    |        |  +-[DOT] '.'
    |        |  |  +-[IDENT] 'cz'
    |        |  |  \-[IDENT] 'test'
    |        |  \-[IDENT] 'ServicePackageT'
    |        \-[ALIAS] 'item'
    \-[WHERE] 'where'
       \-[EQ] '='
          +-[DOT] '.'
          |  +-[IDENT] 'item'
          |  \-[IDENT] 'id'
          \-[NUM_INT] '2450'

07.11.05 17:36:12,980 DEBUG org.hibernate.hql.ast.ErrorCounter throwQueryException() : no errors
07.11.05 17:36:13,090 DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker select << begin [level=1, statement=select]
07.11.05 17:36:13,137 DEBUG org.hibernate.hql.ast.tree.FromElement FromClause{level=1} :  cz.test.ServicePackageT (item) -> servicepac0_
07.11.05 17:36:13,137 DEBUG org.hibernate.hql.ast.tree.FromReferenceNode Resolved :  item -> servicepac0_.sp_id
07.11.05 17:36:13,137 DEBUG org.hibernate.hql.ast.tree.DotNode getDataType() : id -> org.hibernate.type.IntegerType@1b03c1a
07.11.05 17:36:13,137 DEBUG org.hibernate.hql.ast.tree.FromReferenceNode Resolved :  item.id -> servicepac0_.sp_id
07.11.05 17:36:13,152 DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker select : finishing up [level=1, statement=select]
07.11.05 17:36:13,152 DEBUG org.hibernate.hql.ast.HqlSqlWalker processQuery() :  ( SELECT ( FromClause{level=1} public.service_package servicepac0_ ) ( where ( = ( servicepac0_.sp_id servicepac0_.sp_id id ) 2450 ) ) )
07.11.05 17:36:13,168 DEBUG org.hibernate.hql.ast.HqlSqlWalker Derived SELECT clause created.
07.11.05 17:36:13,184 DEBUG org.hibernate.hql.ast.util.JoinProcessor Using FROM fragment [public.service_package servicepac0_]
07.11.05 17:36:13,184 DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker select >> end [level=1, statement=select]
07.11.05 17:36:13,184 DEBUG org.hibernate.hql.ast.AST --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT'  querySpaces (public.service_package)
    +-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
    |  \-[SELECT_EXPR] SelectExpressionImpl: 'servicepac0_.sp_id as sp1_3_' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=item,role=null,tableName=public.service_package,tableAlias=servicepac0_,origin=null,colums={,className=cz.test.ServicePackageT}}}
    +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[item], fromElementByTableAlias=[servicepac0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
    |  \-[FROM_FRAGMENT] FromElement: 'public.service_package servicepac0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=item,role=null,tableName=public.service_package,tableAlias=servicepac0_,origin=null,colums={,className=cz.test.ServicePackageT}}
    \-[WHERE] SqlNode: 'where'
       \-[EQ] SqlNode: '='
          +-[DOT] DotNode: 'servicepac0_.sp_id' {propertyName=id,dereferenceType=4,propertyPath=id,path=item.id,tableAlias=servicepac0_,className=cz.test.ServicePackageT,classAlias=item}
          |  +-[ALIAS_REF] IdentNode: 'servicepac0_.sp_id' {alias=item, className=cz.test.ServicePackageT, tableAlias=servicepac0_}
          |  \-[IDENT] IdentNode: 'id' {originalText=id}
          \-[NUM_INT] LiteralNode: '2450'

07.11.05 17:36:13,184 DEBUG org.hibernate.hql.ast.ErrorCounter throwQueryException() : no errors
07.11.05 17:36:13,230 DEBUG org.hibernate.hql.ast.QueryTranslatorImpl HQL: from cz.test.ServicePackageT item where item.id = 2450
07.11.05 17:36:13,230 DEBUG org.hibernate.hql.ast.QueryTranslatorImpl SQL: select servicepac0_.sp_id as sp1_3_ from public.service_package servicepac0_ where servicepac0_.sp_id=2450
07.11.05 17:36:13,230 DEBUG org.hibernate.hql.ast.ErrorCounter throwQueryException() : no errors
07.11.05 17:36:13,230 DEBUG org.hibernate.jdbc.AbstractBatcher about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
07.11.05 17:36:13,230 DEBUG org.hibernate.SQL select servicepac0_.sp_id as sp1_3_ from public.service_package servicepac0_ where servicepac0_.sp_id=2450
07.11.05 17:36:13,230 DEBUG org.hibernate.jdbc.AbstractBatcher preparing statement
07.11.05 17:36:13,246 DEBUG org.hibernate.jdbc.AbstractBatcher about to open ResultSet (open ResultSets: 0, globally: 0)
07.11.05 17:36:13,246 DEBUG org.hibernate.loader.Loader processing result set
07.11.05 17:36:13,246 DEBUG org.hibernate.loader.Loader result set row: 0
07.11.05 17:36:13,246 DEBUG org.hibernate.type.IntegerType returning '2450' as column: sp1_3_
07.11.05 17:36:13,262 DEBUG org.hibernate.loader.Loader result row: EntityKey[cz.test.ServicePackageT#2450]
07.11.05 17:36:13,262 DEBUG org.hibernate.loader.Loader Initializing object from ResultSet: [cz.test.ServicePackageT#2450]
07.11.05 17:36:13,277 DEBUG org.hibernate.persister.entity.AbstractEntityPersister Hydrating entity: [cz.test.ServicePackageT#2450]
07.11.05 17:36:13,293 DEBUG org.hibernate.loader.Loader done processing result set (1 rows)
07.11.05 17:36:13,293 DEBUG org.hibernate.jdbc.AbstractBatcher about to close ResultSet (open ResultSets: 1, globally: 1)
07.11.05 17:36:13,293 DEBUG org.hibernate.jdbc.AbstractBatcher about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
07.11.05 17:36:13,293 DEBUG org.hibernate.jdbc.AbstractBatcher closing statement
07.11.05 17:36:13,293 DEBUG org.hibernate.loader.Loader total objects hydrated: 1
07.11.05 17:36:13,293 DEBUG org.hibernate.engine.TwoPhaseLoad resolving associations for [cz.test.ServicePackageT#2450]
07.11.05 17:36:13,309 DEBUG org.hibernate.engine.CollectionLoadContext creating collection wrapper:[cz.test.ServicePackageT.spService#2450]
07.11.05 17:36:13,340 DEBUG org.hibernate.engine.TwoPhaseLoad done materializing entity [cz.test.ServicePackageT#2450]
07.11.05 17:36:13,340 DEBUG org.hibernate.engine.StatefulPersistenceContext initializing non-lazy collections
07.11.05 17:36:13,340 DEBUG org.hibernate.event.def.DefaultInitializeCollectionEventListener initializing collection [cz.test.ServicePackageT.spService#2450]
07.11.05 17:36:13,340 DEBUG org.hibernate.event.def.DefaultInitializeCollectionEventListener checking second-level cache
07.11.05 17:36:13,340 DEBUG org.hibernate.event.def.DefaultInitializeCollectionEventListener collection not cached
07.11.05 17:36:13,340 DEBUG org.hibernate.loader.Loader loading collection: [cz.test.ServicePackageT.spService#2450]
07.11.05 17:36:13,340 DEBUG org.hibernate.jdbc.AbstractBatcher about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
07.11.05 17:36:13,340 DEBUG org.hibernate.SQL select spservice0_.sp_id as sp3_2_, spservice0_.sp_service_id as sp1_2_, spservice0_.service_id as formula1_2_, spservice0_.sp_service_id as sp1_4_1_, spservice0_.service_id as service2_4_1_, spservice0_.sp_id as sp3_4_1_, servicet1_.service_id as service1_5_0_ from public.sp_service spservice0_ left outer join public.service servicet1_ on spservice0_.service_id=servicet1_.service_id where spservice0_.sp_id=?
07.11.05 17:36:13,340 DEBUG org.hibernate.jdbc.AbstractBatcher preparing statement
07.11.05 17:36:13,340 DEBUG org.hibernate.type.IntegerType binding '2450' to parameter: 1
07.11.05 17:36:13,371 DEBUG org.hibernate.jdbc.AbstractBatcher about to open ResultSet (open ResultSets: 0, globally: 0)
07.11.05 17:36:13,371 DEBUG org.hibernate.loader.Loader result set contains (possibly empty) collection: [cz.test.ServicePackageT.spService#2450]
07.11.05 17:36:13,371 DEBUG org.hibernate.engine.CollectionLoadContext uninitialized collection: initializing
07.11.05 17:36:13,371 DEBUG org.hibernate.loader.Loader processing result set
07.11.05 17:36:13,371 DEBUG org.hibernate.loader.Loader result set row: 0
07.11.05 17:36:13,371 DEBUG org.hibernate.type.IntegerType returning '16' as column: service1_5_0_
07.11.05 17:36:13,371 DEBUG org.hibernate.type.IntegerType returning '5103' as column: sp1_4_1_
07.11.05 17:36:13,371 DEBUG org.hibernate.loader.Loader result row: EntityKey[cz.test.ServiceT#16], EntityKey[cz.test.SpServiceT#5103]
07.11.05 17:36:13,371 DEBUG org.hibernate.loader.Loader Initializing object from ResultSet: [cz.test.ServiceT#16]
07.11.05 17:36:13,371 DEBUG org.hibernate.persister.entity.AbstractEntityPersister Hydrating entity: [cz.test.ServiceT#16]
07.11.05 17:36:13,371 DEBUG org.hibernate.loader.Loader Initializing object from ResultSet: [cz.test.SpServiceT#5103]
07.11.05 17:36:13,371 DEBUG org.hibernate.persister.entity.AbstractEntityPersister Hydrating entity: [cz.test.SpServiceT#5103]
07.11.05 17:36:13,371 DEBUG org.hibernate.type.IntegerType returning '16' as column: service2_4_1_
07.11.05 17:36:13,387 DEBUG org.hibernate.type.IntegerType returning '2450' as column: sp3_4_1_
07.11.05 17:36:13,387 DEBUG org.hibernate.type.IntegerType returning '2450' as column: sp3_2_
07.11.05 17:36:13,387 DEBUG org.hibernate.loader.Loader found row of collection: [cz.test.ServicePackageT.spService#2450]
07.11.05 17:36:13,387 DEBUG org.hibernate.engine.CollectionLoadContext reading row
07.11.05 17:36:13,387 DEBUG org.hibernate.type.IntegerType returning '5103' as column: sp1_2_
07.11.05 17:36:13,387 DEBUG org.hibernate.event.def.DefaultLoadEventListener loading entity: [cz.test.SpServiceT#5103]
07.11.05 17:36:13,387 DEBUG org.hibernate.event.def.DefaultLoadEventListener attempting to resolve: [cz.test.SpServiceT#5103]
07.11.05 17:36:13,387 DEBUG org.hibernate.event.def.DefaultLoadEventListener resolved object in session cache: [cz.test.SpServiceT#5103]
07.11.05 17:36:13,402 DEBUG org.hibernate.util.SerializationHelper Starting deserialization of object
07.11.05 17:36:13,402 INFO  org.hibernate.type.SerializableType could not read column value from result set: formula1_2_
07.11.05 17:36:13,402 DEBUG org.hibernate.jdbc.AbstractBatcher about to close ResultSet (open ResultSets: 1, globally: 1)
07.11.05 17:36:13,402 DEBUG org.hibernate.jdbc.AbstractBatcher about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
07.11.05 17:36:13,402 DEBUG org.hibernate.jdbc.AbstractBatcher closing statement


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 5:48 am 
Newbie

Joined: Mon Oct 25, 2004 9:18 am
Posts: 7
I'm getting this as well, but with Hibernate 3.1 beta 3. Basically the same mapping and emitted SQL, resulting in the same exception.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 1:49 pm 
Newbie

Joined: Thu Aug 25, 2005 3:59 am
Posts: 7
Location: Czech Republic, Prague
bigdan wrote:
I'm getting this as well, but with Hibernate 3.1 beta 3.


Oh, sorry, completely my fault. I misread my directories when checking old versions of my projekt where it worked. (I didn't use those classes for some time, so I was not sure when was the last time it worked.)

Actually, last version of hibernate where is this thing working is hibernate beta1 with annotations beta4.
Which of course does not answer the question why it stop working...


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.