Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: MappingException:No persister for: net.sf.hibernate.lob.Blob
PostPosted: Wed Sep 08, 2004 9:21 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 8:09 am
Posts: 20
Hibernate version:
2.1.6

Mapping documents:
<class
name="com.xxx.bean.Email"
table="EMAILS"
dynamic-update="true"
dynamic-insert="true"
>
<id
name="emailId"
type="long"
column="EMAIL_ID"
length="22"
>
<generator class="native"/>
</id>

<property
name="emailattachment"
type="java.lang.Object"
update="false" insert="false" >
<column name="EMAIL_ID" />
<column name="EMAILATTACHMENT"/>
</property>

Code between sessionFactory.openSession() and session.close():
InputStream is = new FileInputStream((File)email.getEmailattachment());
byte[] data = new byte[is.available()];
is.read(data);
is.close();

email.setEmailattachment((Object)Hibernate.createBlob(byte[1]));
getHibernateTemplate().save(o);
getHibernateTemplate().flush();
getHibernateTemplate().refresh(o, LockMode.UPGRADE);
writeBlob(data,(Blob)email.getEmailattachment());

protected final void writeBlob(byte[] data, Blob l_blob) throws Exception {
OutputStream out = ((oracle.sql.BLOB) l_blob).getBinaryOutputStream();
out.write(data);
out.close();
}


Full stack trace of any exception that occurs:
java.lang.RuntimeException: java.lang.RuntimeException: org.springframework.orm.hibernate.HibernateSystemException: No persister for: net.sf.hibernate.lob.BlobImpl; nested exception is net.sf.hibernate.MappingException: No persister for: net.sf.hibernate.lob.BlobImpl
Name and version of the database you are using:
Oracle 9

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 11:47 am 
Newbie

Joined: Fri Aug 27, 2004 5:36 pm
Posts: 16
Location: Pittsburgh
Post the code for Email class


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 1:48 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 8:09 am
Posts: 20
Below is the code for email class:

public class Email implements Serializable {

/** identifier field */
private long emailId;

/** identifier field */
private Object emailattachment;

/** full constructor */
public Email(long emailId Object emailattachment) {
this.emailId = emailId;
this.emailattachment = emailattachment;
}

/** default constructor */
public Email() {
}

public long getEmailId() {
return this.emailId;
}

public void setEmailId(long emailId) {
this.emailId = emailId;
}

public Object getEmailattachment() {
return this.emailattachment;
}

public void setEmailattachment(Object emailattachment) {
this.emailattachment = emailattachment;
}


public String toString() {
return new ToStringBuilder(this)
.append("emailId", getEmailId())
.append("emailattachment", getEmailattachment())
.toString();
}

public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof Email) ) return false;
Email castOther = (Email) other;
return new EqualsBuilder()
.append(this.getEmailId(), castOther.getEmailId())
.append(this.getEmailattachment(), castOther.getEmailattachment())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getEmailId())
.append(getEmailattachment())
.toHashCode();
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 3:28 pm 
Newbie

Joined: Fri Aug 27, 2004 5:36 pm
Posts: 16
Location: Pittsburgh
can you declare "java.sql.Blob" or blob instead of object.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 7:53 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 8:09 am
Posts: 20
I know it works when I declare it as java.sql.Blob but I want to declare it as an Object and cast it as a Blob or File as per the requirements..

Is this possible or am trying to be insane?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 10:03 am 
Newbie

Joined: Fri Aug 27, 2004 5:36 pm
Posts: 16
Location: Pittsburgh
If column is of type BLOB on the database side ( assuming Oracle database), I believe hibernate blob type would get picked up and used for transaction. I think thats why hibernate its using default imp of blob that comes with it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 10:12 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 8:09 am
Posts: 20
yes, it is defined as a Blob in the database but as an Object in the mapping files and the persistence class.
so, why am I getting this error? Is it looking for a Blob?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 10:37 am 
Newbie

Joined: Fri Aug 27, 2004 5:36 pm
Posts: 16
Location: Pittsburgh
i am no expert .. this is my theory and correct me if i am wrong..

even if its declared as Object, it needs some type of behaviour or characteristics. And when you declare as object, the default mapping to column type BLOB is BlobImpl ( in hibernate).

Do some system out and find whats the instance class behind it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 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.