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!