-->
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: Hibernate with Apache James-java.io.StreamCorruptedException
PostPosted: Tue Oct 27, 2009 12:00 pm 
Newbie

Joined: Tue Oct 27, 2009 11:49 am
Posts: 2
Hi Everybody,

I am new to this forum and relatively new to Hibernate.

I am trying access Apache Mail server Inbox MySql table through Hibernate. The Inbox data is coming back from the query. But later I have to process the MessageBody column which is a 'longblob' in Mysql like I have shown in the code below to get the MimeMessage object. I have checked a few times with Apache James code to see if I am doing this correctly,and I am. But I the exception below. It seems to be a field mapping issue at the first sight. Anyone, please help.

------------------------------------------------------------------------------

public class MailWrapperTest {

public static void main(String[] atgs) {
try {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Query query = session.createQuery("from Inbox where id.messageName = :messageName");
query.setParameter("messageName", "Mail1254445805920-7");
List results = query.list();
Inbox inbox = (Inbox)results.get(0);
session.refresh(inbox, LockMode.UPGRADE);
byte[] messageBodyBytes = inbox.getMessageBody();
ObjectInputStream objectInputStream = new ObjectInputStream (new ByteArrayInputStream(messageBodyBytes));
Object obj = objectInputStream.readObject();
objectInputStream.close();
} catch(Exception e){
e.printStackTrace();
}


}
-------------------------------------------------------------------------------------------------
java.io.StreamCorruptedException: invalid stream header: 52657475
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at com.daybreak.james.test.MailWrapperTest.main(MailWrapperTest.java:33)


Top
 Profile  
 
 Post subject: Re: Hibernate with Apache James-java.io.StreamCorruptedException
PostPosted: Tue Oct 27, 2009 3:38 pm 
Newbie

Joined: Tue Oct 27, 2009 11:49 am
Posts: 2
Below is the Inbox code and Hibernate version is 3.4, Mysql version is 5.1.

This is a showstopper. Help!!!
------------------------------------------------------------------------

// Generated Sep 24, 2009 10:10:55 AM by Hibernate Tools 3.2.1.GA


import java.util.Date;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
* Inbox generated by hbm2java
*/
@Entity
@Table(name="inbox"
,catalog="james"
)
public class Inbox implements java.io.Serializable {


private InboxId id;
private String messageState;
private String errorMessage;
private String sender;
private String recipients;
private String remoteHost;
private String remoteAddr;
private byte[] messageBody;
private byte[] messageAttributes;
private Date lastUpdated;

public Inbox() {
}


public Inbox(InboxId id, String messageState, String recipients, String remoteHost, String remoteAddr, byte[] messageBody, Date lastUpdated) {
this.id = id;
this.messageState = messageState;
this.recipients = recipients;
this.remoteHost = remoteHost;
this.remoteAddr = remoteAddr;
this.messageBody = messageBody;
this.lastUpdated = lastUpdated;
}
public Inbox(InboxId id, String messageState, String errorMessage, String sender, String recipients, String remoteHost, String remoteAddr, byte[] messageBody, byte[] messageAttributes, Date lastUpdated) {
this.id = id;
this.messageState = messageState;
this.errorMessage = errorMessage;
this.sender = sender;
this.recipients = recipients;
this.remoteHost = remoteHost;
this.remoteAddr = remoteAddr;
this.messageBody = messageBody;
this.messageAttributes = messageAttributes;
this.lastUpdated = lastUpdated;
}

@EmbeddedId

@AttributeOverrides( {
@AttributeOverride(name="repositoryName", column=@Column(name="repository_name", nullable=false, length=100) ),
@AttributeOverride(name="messageName", column=@Column(name="message_name", nullable=false, length=200) ) } )
public InboxId getId() {
return this.id;
}

public void setId(InboxId id) {
this.id = id;
}

@Column(name="message_state", nullable=false, length=30)
public String getMessageState() {
return this.messageState;
}

public void setMessageState(String messageState) {
this.messageState = messageState;
}

@Column(name="error_message", length=200)
public String getErrorMessage() {
return this.errorMessage;
}

public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}

@Column(name="sender")
public String getSender() {
return this.sender;
}

public void setSender(String sender) {
this.sender = sender;
}

@Column(name="recipients", nullable=false, length=65535)
public String getRecipients() {
return this.recipients;
}

public void setRecipients(String recipients) {
this.recipients = recipients;
}

@Column(name="remote_host", nullable=false)
public String getRemoteHost() {
return this.remoteHost;
}

public void setRemoteHost(String remoteHost) {
this.remoteHost = remoteHost;
}

@Column(name="remote_addr", nullable=false, length=20)
public String getRemoteAddr() {
return this.remoteAddr;
}

public void setRemoteAddr(String remoteAddr) {
this.remoteAddr = remoteAddr;
}

@Column(name="message_body", nullable=false)
public byte[] getMessageBody() {
return this.messageBody;
}

public void setMessageBody(byte[] messageBody) {
this.messageBody = messageBody;
}

@Column(name="message_attributes")
public byte[] getMessageAttributes() {
return this.messageAttributes;
}

public void setMessageAttributes(byte[] messageAttributes) {
this.messageAttributes = messageAttributes;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="last_updated", nullable=false, length=19)
public Date getLastUpdated() {
return this.lastUpdated;
}

public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}




}


Top
 Profile  
 
 Post subject: Re: Hibernate with Apache James-java.io.StreamCorruptedException
PostPosted: Fri Oct 11, 2013 11:57 am 
Newbie

Joined: Fri Oct 11, 2013 11:56 am
Posts: 1
Hi,

Did you find a solution for this? I have the same issue.


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.