Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

EJB with Rest service to return a blob

DLopezAug 11 2015 — edited Aug 14 2015

Hi,

I've been working with EJB and Rest Services and now I have this situation.

I'm trying to present an image saved on my DB as a blob, but when I test my service I get no results.

My entity as the following code for the blob, self generated

private byte[] thememo;

    public byte[] getThememo() {

        return thememo;

    }

    public void setThememo(byte[] thememo) {

        this.thememo = thememo;

    }

and this are the queries, both to return the same, that I've added

@NamedQuery(name = "Memos.findPhoto", query = "select o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101"),

@NamedQuery(name = "Memos.getPhoto", query = "select 'image/jpeg', o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101")

when looking for something that would explain me on how to accomplish what I want I found a link indicating to add this 'image/jpeg', before the column that as the blob

and when I add those queries as functions to my SessionBean through facade this are the results I get

    /** <code>select o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101</code> */

    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

    public List<Byte> getMemosFindPhoto(String recid) {

        return em.createNamedQuery("Memos.findPhoto", Memos.class).setParameter("recid", recid).getResultList();

    }

    /** <code>select 'image/jpeg', o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101</code> */

    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

    public List<Object[]> getMemosGetPhoto(String recid) {

        return em.createNamedQuery("Memos.getPhoto", Memos.class).setParameter("recid", recid).getResultList();

    }

The first gives me a List of Bytes and the other a List of Object Array, and the only thing I want to return is the blob as image.

Both returns in my SessionBean are giving errors, 'Incompatible types' but this was generated.

Without those functions, when I try to add the service to my JAXB schema it won't allow it.

What am I doing wrong or what am I missing?

I'm using JDev 12.1.3.0

Thanks

and when I add 'image/jpeg', 'image/jpeg','image/jpeg',

This post has been answered by kdario on Aug 12 2015
Jump to Answer

Comments

InoL

...be displayed on an apex page somehow

To display an image, just use Display Image item type.

If not an image, what documents are you talking about to be displayed? Typically, documents are downloaded. For PDF, there is a plugin to show the pdf directly on a page.

http://www.apex-plugin.com/oracle-apex-plugins/item-plugin/pdfembedded_337.html

raudabat
Answer

I think you are missing the htp.init;   at the start of your routine. This will happen in Firefox if this is not set.

Hope this works.

Tom

Marked as Answer by newjack · Sep 27 2020
newjack

This is a pdf. I will give the plugin a look.

newjack

This was helpful. The pdf is not rendering but the pdf container displayed.  Thank you!

1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 11 2015
Added on Aug 11 2015
11 comments
1,227 views