aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes Entity EJB and BLOB Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "Entity EJB and BLOB" Watch "Entity EJB and BLOB" New topic
Author

Entity EJB and BLOB

Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75
Hello there
Does anybody know how difficult is it to store data in an Oracle table with Blob fields using an Entity EJB ?
I have made a few try with .. no success
EJB deployement, Database mapping and so are okay but it looks like it's not possible to store 'normal' data (varchar, integer..) and Blob at the same time.
NB: I'm using BEA WebLogic 7 & Oracle 8i
Any info about how to proceed ?
Thanx


Franck<p>--------------------
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Are you using CMP or BMP?
Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75
Are you using CMP or BMP?

I first tried with CMP but I coudn't do anything 'properly'...
Since i'm only interested in saving data, i thought Entity would be perfect.
I guess I was wrong
Anyway I would appreciate expert's point of view about Entity EJBs and the use of BLOBs...
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Have you tried this?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
To fully answer the quesion, I believe that knowing why BLOBs are being used is appropriate. You mention that it doesn't work when using standard types?!
Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75
Lasse,
Yes, i checked those documents before asking here.
(NB : There is actually a mistake in the sample provided <dbms_column-type> should be replaced by <dbms-column-type>
It's fine for the deploytement descriptor and how to map data.
Problems come after that, in the EJB Bean.
How to set the Blob values ??
As I said, standard types insert *works*.
You're right Dana, maybe a little bit more of info could help :
- Database Table to be mapped :
OBJ_UNIT_NBR NUMBER (8) NOT NULL,
OBJ_DESC NUMBER (8) NOT NULL,
OBJ_IMG BLOB
The OBJ_IMG is nothing more than a small picture (about 5/6kb)
- Mapping rules as described in the weblogic-cmp-rdbms-jar.xml file
<..>
<table-map>
<table-name>OBJ</table-name>
<field-map>
<cmp-field>ObjectUnitNumber</cmp-field>
<dbms-column>OBJ_UNIT_NBR</dbms-column>
</field-map>
<field-map>
<cmp-field>ObjectDescription</cmp-field>
<dbms-column>OBJ_DESC</dbms-column>
</field-map>
<field-map>
<cmp-field>ObjectPicture</cmp-field>
<dbms-column>OBJ_IMG</dbms-column>
<dbms-column-type>OracleBlob</dbms-column-type>
</field-map>
</table-map>
<..>
I can easily call the ejbCreate method of my EJB Bean (Remote) class with the mandatory parameters : OBJ_UNIT_NBR and OBJ_DESC.
But how to insert the Blob data ??
Looks like Blob data first need to be inserted as 'empty' :
INSERT INTO OBJ (OBJ_UNIT_NBR, OBJ_DESC, OBJ_IMG) VALUES( ?, ?, EMPTY_BLOB())
then selected in order to refer to the Blob to save in database :
SELECT OBJ_IMG FROM OBJ WHERE OBJ_UNIT_NBR = <ObjId> FOR UPDATE
finally transfert data to the Blob :
Blob objImage = objResultSet.getBlob("OBJ_IMG");
OutputStream out = ((weblogic.jdbc.rmi.SerialOracleBlob)objImage).getBinaryOutputStream();
out.write(myArrayOfBytes);

I don't see how to perform the same steps in an Entity EJB....
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Are you using a byte[] as the type for the field you're persisting? (i.e. setObjectPicture(byte[] img) or something like that)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Entity EJB and BLOB
 
Similar Threads
Problems with file upload
A Java program or an ETL?
how to create BLOB and CLOB data
Image insertion into database through JPA
how to use large objects,images blob