karabara
karabara

Reputation: 557

How to get Clob data from native query?

I have tried this:

List resultList = session.createSQLQuery("select pack.FuncName ClobData from dual").list()

whereis FuncName it is the name of function that returns clob data. But in resultList I see some proxy object (for example $Proxy189). I believe... It is something simple and I don't want ising reflection to get my data.

Upvotes: 0

Views: 6919

Answers (2)

LateralFractal
LateralFractal

Reputation: 341

I found this solved a similar problem for me without requiring Proxies or custom converters:

createSQLQuery("...").addScalar("clob_field", StandardBasicTypes.MATERIALIZED_CLOB);

Upvotes: 1

Nacho Cougil
Nacho Cougil

Reputation: 562

Yes, launching SQL querys directly is not a good idea (by default) using an ORM.

Probably one of the solutions that could fit better in your case will be mapping the CLOB data returned by your FuncName to a new non-managed entity (if it's the case). You can create a new entity that fit your requirements and get the data. You can read about it here for example.

Of course other solution can be, launch the function that prepares/buils the clob data, save it (for example in a temporary table structure) and then loading it using the @Lob annotation. Check the reference about Property mapping with annotations

Upvotes: 0

Related Questions