• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Entity EJB and BLOB

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using CMP or BMP?
 
Franck Tranchant
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried this?
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using a byte[] as the type for the field you're persisting? (i.e. setObjectPicture(byte[] img) or something like that)
 
reply
    Bookmark Topic Watch Topic
  • New Topic