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: SerializationException again. Now with @Formula column
PostPosted: Sun Feb 25, 2007 1:32 pm 
Newbie

Joined: Mon Aug 28, 2006 6:31 am
Posts: 16
Hello,

again a stupid question, but i can't find a solution in a forum/goolge:

My mapping
Code:
@MappedSuperclass
public class Entity implements Serializable{
@Id
Long id;
....
}

@Entity
public class Bid extends Entity{
private static final long serialVersionUID = ...;
}

@Entity
public class Offer extends Entity{
private static final long serialVersionUID = ...;

@Formula("( select distinct bid.ID from rwo.BID bid where bid.OFFER_ID = ID and bid.SUCCESSFUL = 't' )")
private Bid successfulBid;
...
}




If i query to find all Offers (especially with successfulBid) Hibernate produces followoing Query fragment:

Code:
.....
   ( select
        distinct bid.ID
    from
        rwo.BID bid
    where
        bid.OFFER_ID = offer0_.ID
        and bid.SUCCESSFUL = 't' ) as formula11_
....


which is as in a mapping expected. But as soon as the query picks a result with an existing successful bid it throws a strange exception:

Code:
16:45:11,214 INFO  [SerializableType] could not read column value from result set: formula11_; could not deserialize
16:45:11,230 ERROR [ExceptionFilter] uncaught exception
....
Caused by: javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize
        at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
        at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
...
Caused by: java.io.StreamCorruptedException: invalid stream header: 31313739
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
        at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:252)
        at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209)
        ... 135 more
16:45:11,636 ERROR [DebugPageHandler] redirecting to debug page
java.io.StreamCorruptedException: invalid stream header: 31313739
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
        at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:252)
...

After some digging i've found, that jdbc query deliver a proper result set with a byte[] for the bid id (Long). This byte[] has already a byte representation of a long id (e.g. [49],[49],[51]...) wich is absolutly correct. Then this byte[] will be transormed with some Hibernate magic and fails at the constructor call of CustomObjectInputStream.class : method "readStreamHeader" of superclass doesn't recognize the stream as correct here :
Code:
short s0 = bin.readShort();
   short s1 = bin.readShort();
   if (s0 != STREAM_MAGIC || s1 != STREAM_VERSION) {
       throw new StreamCorruptedException(...)}
.

Does anybody have an idea?


The second question is a common issue on @Formula. Is it a good practice to use @Formula columns? I mean, an offer can get a successful bid, wich is stored in BID table. If i wish to query the ended Offers (see the simplified mapping above) with a successful bids, i create a HQL-Query with "... where Offer.successfulBid not null ..." even if "successfulBid" is a virtual column (no redundant references and fk-constraints are stored for successful bid in an Offer-Table). Is there any performance bottlenecks? Why i can't use the HQL pieces as @Fromula strings?

Sorry for my english
and thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 7:32 pm 
Newbie

Joined: Mon Aug 28, 2006 6:31 am
Posts: 16
Ok, @Formula query delivers a long value. Naturally, it can't be deserialized as a Bid. I need to fetch a whole bid, not only the id. So the @Formula doesn't propper for me.


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.