-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: ORACLE SQLSERVER BYTE[]
PostPosted: Wed Feb 04, 2004 1:06 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
Hello

I am having problem when moving the code from ORACLE to SQL SERVER. I mapped the byte [] to BLOB by using the custom type in ORACLE. It worked fine.

I moved the code to work with sqlserver and now I have IMAGE as the column type in SQL SERVER 7.0. When i execute the code i get an exception.

I am using the schemaexport tool of hibernate to generate the DDL. Please point me to the right direction.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 1:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Really useless without a better error description. What exception? What type are you using now?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 2:19 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="WfInstanceData"
table="WfInstance"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="instanceId"
column="instanceId"
type="int"
unsaved-value="0"
>
<generator class="increment">
</generator>
</id>


<property
name="data"
type="BinaryBlobType"
update="true"
insert="true"
column="data"
/>


</class>

</hibernate-mapping>

the ddl thats generated from the above is

create table WfInstance (
instanceId int ,
data IMAGE null,
primary key (instanceId)
);


/**
* @hibernate.class table="WfInstance"
*/
public class WfInstanceData {

private int instanceId;
private WfTemplateData templateRefId;
private byte [] data;
/**
* @return
* @hibernate.property column="data" type="BinaryBlobType"
*/
public byte [] getData() {
return data;
}


public void setData(byte [] string) {
data = string;
}

}



When i execute i get the following error.

net.sf.hibernate.JDBCException: could not insert: [com. . .wfengpersist.model.WfInstanceData#1]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:479)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:443)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2261)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at com. . .wfengpersist.dao.WfEngineDataDAOImpl.addInstance(WfEngineDataDAOImpl.java:45)
at com. . .wfengpersist.dao.WfTemplateDAOTest.testSaveTemplate(WfTemplateDAOTest.java:74)
at com. . .wfengpersist.ejb.WfTemplateEJB.addTemplate(WfTemplateEJB.java:45)
at com. . .wfengpersist.ejb.WfTemplateEJB_5hsagc_EOImpl.addTemplate(WfTemplateEJB_5hsagc_EOImpl.java:37)
at com. . .wfengpersist.ejb.WfTemplateEJB_5hsagc_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:360)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:329)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:140)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:121)
Caused by: java.sql.SQLException: This JDBC 2.0 method is not implemented
at weblogic.jdbc.mssqlserver4.TdsPreparedStatement.setBlob(TdsPreparedStatement.java:101)
at weblogic.jdbc.pool.PreparedStatement.setBlob(PreparedStatement.java:158)
at com. . .wfengpersist.model.BinaryBlobType.nullSafeSet(BinaryBlobType.java:43)
at net.sf.hibernate.type.CustomType.nullSafeSet(CustomType.java:118)
at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:394)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:467)
... 16 more
<Feb 4, 2004 11:53:29 AM CST> <Error> <J2EE> <Error deploying application wfengineEjb:


WITH ORACLE EVERYTHING GOES FINE.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 2:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Driver problem. Rewerite your custom type to use something else than setBlob like setInputStream or something might help. Examples are in the Wiki area.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 3:23 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
then the portability of the code across different databases is limited. right?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 3:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Right. Complain to your db/driver manufacturer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 4:53 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
Hi,

Thanks for your kind reply. I would like to reword my question. I have a field of type TEXT in sqlserver and the same field is of type CLOB in oracle. What do i need to do in my code if i need to make my code portable. Specifically how should my mapping be and the getters and setters for that field.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 5:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
First try to access it portably in JDBC. Then do the same in your user type.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 5:13 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
kic wrote:
I have a field of type TEXT in sqlserver and the same field is of type CLOB in oracle. What do i need to do in my code if i need to make my code portable. Specifically how should my mapping be and the getters and setters for that field.


Map your property with a type text. This will be a TEXT under SQLServer and a CLOB under Oracle.

It works like a charm and is portable (at least in our case) - and without having to write any custom type ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 5:18 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
brenuart :

Thank you very much. I did do that. But i get a (strange) classcastexception. Please take a look at source and let me know what i am doing wrong.

/**
* @return
* @hibernate.property column="data" type="text"
*/
public String getData() {
return data;
}





Hibernate: insert into WfTemplate (data, isLatest, modifiedBy, ModifiedTime, sequence, templateId, versionNum, templateRefId) values (?, ?, ?, ?, ?, ?, ?, ?)
com..truaccess.wfengpersist.exceptions.WfEngineDAException: [B
java.lang.ClassCastException: [B
at net.sf.hibernate.type.TextType.set(TextType.java:21)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:394)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:467)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:443)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2261)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at com..truaccess.wfengpersist.dao.WfTemplateDataDAOImpl.addTemplate(WfTemplateDataDAOImpl.java:54)
at com..truaccess.wfengpersist.dao.WfTemplateDAOTest.testSaveTemplate(WfTemplateDAOTest.java:56)
at com..truaccess.wfengpersist.ejb.WfTemplateEJB.addTemplate(WfTemplateEJB.java:45)
at com..truaccess.wfengpersist.ejb.WfTemplateEJB_5hsagc_EOImpl.addTemplate(WfTemplateEJB_5hsagc_EOImpl.java:37)
at com..truaccess.wfengpersist.ejb.WfTemplateEJB_5hsagc_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:360)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:329)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:140)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:121)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 5:34 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Hibernate gets a ClassCast because it got something else than a string when getting the data to persist from your Java class.

(have a look at hibernate sources, line 21 is a type casting to a String)

String since your getData() method returns a String...

You are using XDoclet to generate your HBM... check the generated HBM and make sure they reflect your data type. Might be a good idea to post the mapping for the class causing the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 5:42 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
<property
name="data"
type="text"
update="true"
insert="true"
column="data"
/>


In SQL SERVER the
data type is text and size is 16 and nulls are allowed.


What am i doing differently that make my code not work?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 5:51 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
kic wrote:
In SQL SERVER the
data type is text and size is 16 and nulls are allowed.


This is normal - but I don't think the mapping is the problem. There is something else in your code we don't see that breaks it...

As I said, Hibernate extracts a value from somwhere which is NOT a string and assign it to a TEXT type... Where does it come and what is the actual type? That's the question...

(too bad the ClassCastException doesn't include the actual type - would already have saved me lots of time)


kic wrote:
What am i doing differently that make my code not work?


That's the question ;-)

Please, raise Log4J debug level for Hibernate and have a look at what it says. Hibernate can become very verbose...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 11:07 am 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
Hello:

Thanks. I got the mistake. It was a coding mistake. Thank you very much for pointing me to the right direction.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 11:14 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
kic wrote:
Thanks. I got the mistake. It was a coding mistake. Thank you very much for pointing me to the right direction.


Would be nice if you could share your mistake with us...
Other people could learn from it ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.