You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Stefan Schmidt <sc...@gmail.com> on 2005/07/29 08:20:52 UTC
access a BLOB coloumn from a CMP EJB
Hi,
I am trying to access a (MySQL) MEDIUMBLOB coloumn from a CMP EJB. There
are some tips @ Wiki but I still can't figure it out.
Here are my artefacts:
openejb-jar.xml:
<cmp-field-mapping>
<cmp-field-name>image</cmp-field-name>
<table-column>image</table-column>
<sql-type>BLOB</sql-type>
<type-converter>org.tranql.sql.typeconverter.SerializableConverter</type-converter>
</cmp-field-mapping>
CMP EJB fields:
public byte[] getImage();
public void setImage(byte[] image);
When trying to access this coloumn from my Session EJB :
book.getImage();
I get:
javax.transaction.TransactionRolledbackException: Unable to load data
for field
at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:126)
at
org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
at
org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82)
at org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:234)
at
org.openejb.proxy.EJBMethodInterceptor.intercept(EJBMethodInterceptor.java:129)
at
org.openejb.proxy.EntityEJBObject$$EnhancerByCGLIB$$227af363.getImage(<generated>)
at com.ibm.dw.bookshop.ejb.BookShopBean.getBooks(BookShopBean.java:135)
...
Do I have to write my own /Type**Converter to get it right?
Could anyone provide a short example on this (preferably write it on the
wiki so everyone can see it)?
The wiki link:
http://wiki.apache.org/geronimo/Working_with_Enterprise_JavaBeans
Thanks,
Stefan
/
Re: access a BLOB coloumn from a CMP EJB
Posted by Jeremy Boynes <jb...@apache.org>.
Aaron Mulder wrote:
> On Sun, 31 Jul 2005, Jeremy Boynes wrote:
>
>>Neither - Geronimo can use whichever version it chooses.
>
>
> Um, OK, then I guess Geronimo needs some more information to
> decide which to use. What's the plan for testing and finalizing TranQL
> v1.0?
1.0 is basically frozen except for bug fixes. This could be considered a
bug fix and might be worth backporting - do you think it should be included?
When do you expect that and when do you expect v1.1 to be tested
> and finalized?
"When its done"
> What other changes are in store for v1.1?
Mian focus for me and Matt is additional dialects especially DB2.
Is OpenEJB
> 2.0-SHAPSHOT dependent on TranQL 1.1-SNAPSHOT or can OpenEJB also choose
> v1.0?
The itest relies on 1.1 as I wanted to highlight the problem Stephen was
seeing. The runtime can use either although the default way in which
byte[] values get persisted will be different.
Should this change be backported to TranQL 1.0?
Up to you. I did not want to impact existing Geronimo applications.
--
Jeremy
Re: access a BLOB coloumn from a CMP EJB
Posted by Aaron Mulder <am...@alumni.princeton.edu>.
On Sun, 31 Jul 2005, Jeremy Boynes wrote:
> Neither - Geronimo can use whichever version it chooses.
Um, OK, then I guess Geronimo needs some more information to
decide which to use. What's the plan for testing and finalizing TranQL
v1.0? When do you expect that and when do you expect v1.1 to be tested
and finalized? What other changes are in store for v1.1? Is OpenEJB
2.0-SHAPSHOT dependent on TranQL 1.1-SNAPSHOT or can OpenEJB also choose
v1.0? Should this change be backported to TranQL 1.0?
Thanks,
Aaron
> This change means that 1.1 has a default byte[] binding that stores the
> data directly in the database rather than generically serializing the
> array. This is more likely to work with other applications than the
> serialized form.
>
> --
> Jeremy
>
Re: access a BLOB coloumn from a CMP EJB
Posted by Jeremy Boynes <jb...@apache.org>.
Aaron Mulder wrote:
> Sorry, what's the difference between TranQL 1.0 and 1.1? Is 1.0
> targeted to Geroniom M4 or Geronimo 1.0?
>
Neither - Geronimo can use whichever version it chooses.
This change means that 1.1 has a default byte[] binding that stores the
data directly in the database rather than generically serializing the
array. This is more likely to work with other applications than the
serialized form.
--
Jeremy
Re: access a BLOB coloumn from a CMP EJB
Posted by Aaron Mulder <am...@alumni.princeton.edu>.
Sorry, what's the difference between TranQL 1.0 and 1.1? Is 1.0
targeted to Geroniom M4 or Geronimo 1.0?
Thanks,
Aaron
On Sun, 31 Jul 2005, Jeremy Boynes wrote:
> ...
> This will require an update to use OpenEJB HEAD (2.0-SNAPSHOT) and
> TranQL HEAD (1.1-SNAPSHOT)
Re: access a BLOB coloumn from a CMP EJB
Posted by Jeremy Boynes <jb...@apache.org>.
Jeremy Boynes wrote:
> Stefan Schmidt wrote:
>
>> Gianny, Jeremy,
>>
>> I got it! Apparently, the problem was on my site. I actually loaded
>> the Blobs (images) directly via the PhpMyAdmin Gui (there is a file
>> upload function) and then tried to access these blob fields via the
>> EJB. To dig into my problem I tried the
>> org.openejb.test.entity.cmp2.StorageTests on MySQL and this worked. So
>> I ended up updating my blob fields via the EJB (loading the files via
>> the EJB rather than PhpMyAdmin ) and now it works! Seems like the
>> PhpMyAdmin does something with the blob that Java doesn't like...
>>
>
> I think its the other way around - I am guessing that PhpMyAdmin is
> inserting the bytes directly but when you use the EJB it is Serializing
> the array and writing the serialized data stream.
>
> When the EJB tries to read the bytes inserted by PhpMyAdmin it gets the
> raw data rather than the bytes for ObjectInputStream and is raising an
> error.
>
> I think this is a bug as we should be able to support the raw data
> format correctly - we need to play nice with other applications.
>
I updated the OpenEJB itest to check that the data stored in the column
was what was being passed to the accessor i.e. that is it not bing
Serialized. I added a new binding to TranQL (1.1-SNAPSHOT) to make this
test work so I think you will now be able to mix access between your
admin tool and the EJB.
This will require an update to use OpenEJB HEAD (2.0-SNAPSHOT) and
TranQL HEAD (1.1-SNAPSHOT)
--
Jeremy
Re: access a BLOB coloumn from a CMP EJB
Posted by Jeremy Boynes <jb...@apache.org>.
Stefan Schmidt wrote:
> Gianny, Jeremy,
>
> I got it! Apparently, the problem was on my site. I actually loaded the
> Blobs (images) directly via the PhpMyAdmin Gui (there is a file upload
> function) and then tried to access these blob fields via the EJB. To dig
> into my problem I tried the org.openejb.test.entity.cmp2.StorageTests on
> MySQL and this worked. So I ended up updating my blob fields via the EJB
> (loading the files via the EJB rather than PhpMyAdmin ) and now it
> works! Seems like the PhpMyAdmin does something with the blob that Java
> doesn't like...
>
I think its the other way around - I am guessing that PhpMyAdmin is
inserting the bytes directly but when you use the EJB it is Serializing
the array and writing the serialized data stream.
When the EJB tries to read the bytes inserted by PhpMyAdmin it gets the
raw data rather than the bytes for ObjectInputStream and is raising an
error.
I think this is a bug as we should be able to support the raw data
format correctly - we need to play nice with other applications.
--
Jeremy
Re: access a BLOB coloumn from a CMP EJB
Posted by Gianny Damour <gi...@optusnet.com.au>.
I was trying to find the root cause and I have added an integration test
to test the storage of a byte[] into a BLOB (see
org.openejb.test.entity.cmp2.StorageTests in OpenEJB itests). It seems
that it works; at least for Derby.
BTW, by default a field having the type byte[] is automatically
serialized, so one should not need to explicitly declare a
SerializableConverter.
Thanks,
Gianny
On 30/07/2005 9:51 AM, Jeremy Boynes wrote:
> Stefan Schmidt wrote:
>
>> Jeremy,
>>
>> That was one of the weired things here - there is no true root cause:
>>
>> 08:42:29,134 WARN [SystemExceptionInterceptor] BookBean
>> javax.transaction.TransactionRolledbackException: Unable to load data
>> for field
>> at
>> org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:126)
>>
>
>
> OpenEJB is dropping the root cause for some reason (claims it can't
> initCause() and doesn't log the lost info). Please can you open a bug
> for that as I think we'll lose diagnostic info for any problem
> encountered by the persistence code.
>
> I'll try and reproduce and get the byte[] mapping working.
> --
> Jeremy
>
>
Re: access a BLOB coloumn from a CMP EJB
Posted by Jeremy Boynes <jb...@apache.org>.
Stefan Schmidt wrote:
> Jeremy,
>
> That was one of the weired things here - there is no true root cause:
>
> 08:42:29,134 WARN [SystemExceptionInterceptor] BookBean
> javax.transaction.TransactionRolledbackException: Unable to load data
> for field
> at
> org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:126)
>
OpenEJB is dropping the root cause for some reason (claims it can't
initCause() and doesn't log the lost info). Please can you open a bug
for that as I think we'll lose diagnostic info for any problem
encountered by the persistence code.
I'll try and reproduce and get the byte[] mapping working.
--
Jeremy
Re: access a BLOB coloumn from a CMP EJB
Posted by Stefan Schmidt <sc...@gmail.com>.
Jeremy,
That was one of the weired things here - there is no true root cause:
08:42:29,134 WARN [SystemExceptionInterceptor] BookBean
javax.transaction.TransactionRolledbackException: Unable to load data
for field
at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:126)
at
org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
at
org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82)
at org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:234)
at
org.openejb.proxy.EJBMethodInterceptor.intercept(EJBMethodInterceptor.java:129)
at
org.openejb.proxy.EntityEJBObject$$EnhancerByCGLIB$$aec278d4.getImage(<generated>)
at com.ibm.dw.bookshop.ejb.BookShopBean.getBooks(BookShopBean.java:126)
at
com.ibm.dw.bookshop.ejb.BookShopBean$$FastClassByCGLIB$$64a01afb.invoke(<generated>)
at
org.openejb.dispatch.AbstractMethodOperation.invoke(AbstractMethodOperation.java:90)
at org.openejb.slsb.BusinessMethod.execute(BusinessMethod.java:67)
at
org.openejb.dispatch.DispatchInterceptor.invoke(DispatchInterceptor.java:72)
at
org.openejb.slsb.HandlerChainInterceptor.invoke(HandlerChainInterceptor.java:102)
at
org.apache.geronimo.naming.java.ComponentContextInterceptor.invoke(ComponentContextInterceptor.java:56)
at
org.openejb.ConnectionTrackingInterceptor.invoke(ConnectionTrackingInterceptor.java:81)
at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:119)
at
org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
at
org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:98)
at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:140)
at
org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
at
org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82)
at org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:234)
at
org.openejb.GenericEJBContainer$$FastClassByCGLIB$$60a0c356.invoke(<generated>)
at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
at
org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)
at
org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:118)
at
org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:719)
at
org.apache.geronimo.gbean.runtime.RawInvoker.invoke(RawInvoker.java:57)
at
org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(RawOperationInvoker.java:36)
at
org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(ProxyMethodInterceptor.java:94)
at
org.openejb.EJBContainer$$EnhancerByCGLIB$$c80c52a0.invoke(<generated>)
at
org.openejb.server.axis.EJBContainerProvider.processMessage(EJBContainerProvider.java:103)
at
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at
org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at
org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
at
org.apache.geronimo.axis.server.AxisWebServiceContainer.invoke(AxisWebServiceContainer.java:115)
at
org.apache.geronimo.jetty.JettyEJBWebServiceContext.handle(JettyEJBWebServiceContext.java:162)
at org.mortbay.http.HttpServer.service(HttpServer.java:954)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
This is all I get...
Thanks for your your help and hopefully the mapping for the array
serialization is not too hard to implement :-). I think it would be a
great feature once it is there!
Stefan
Jeremy Boynes wrote:
> It is probably simplest if we add byte[] as a mapped type inside
> TranQL as that will result in the bytes being written to the LOB
> rather than having it serialize an array object. I will try to add
> that mapping over the weekend.
>
> Having said that, the Serializable converter should work if you are
> inserting the LOB using the EJB (and not directly through JDBC). The
> stack you sent is from when we decided to roll the transaction back,
> there should be another stacktrace in the log showing the true root
> cause - can you post that one please.
>
> --
> Jeremy
>
> Stefan Schmidt wrote:
>
>> Hi,
>>
>> I am trying to access a (MySQL) MEDIUMBLOB coloumn from a CMP EJB.
>> There are some tips @ Wiki but I still can't figure it out.
>>
>> Here are my artefacts:
>>
>> openejb-jar.xml:
>>
>> <cmp-field-mapping>
>> <cmp-field-name>image</cmp-field-name>
>> <table-column>image</table-column>
>> <sql-type>BLOB</sql-type>
>>
>> <type-converter>org.tranql.sql.typeconverter.SerializableConverter</type-converter>
>>
>> </cmp-field-mapping>
>>
>>
>> CMP EJB fields:
>>
>> public byte[] getImage();
>>
>> public void setImage(byte[] image);
>>
>>
>> When trying to access this coloumn from my Session EJB :
>>
>> book.getImage();
>>
>> I get:
>>
>> javax.transaction.TransactionRolledbackException: Unable to load data
>> for field
>> at
>> org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:126)
>>
>> at
>> org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
>>
>> at
>> org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82)
>>
>> at
>> org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:234)
>> at
>> org.openejb.proxy.EJBMethodInterceptor.intercept(EJBMethodInterceptor.java:129)
>>
>> at
>> org.openejb.proxy.EntityEJBObject$$EnhancerByCGLIB$$227af363.getImage(<generated>)
>>
>> at
>> com.ibm.dw.bookshop.ejb.BookShopBean.getBooks(BookShopBean.java:135)
>> ...
>>
>> Do I have to write my own /Type**Converter to get it right?
>>
>> Could anyone provide a short example on this (preferably write it on
>> the wiki so everyone can see it)?
>>
>> The wiki link:
>> http://wiki.apache.org/geronimo/Working_with_Enterprise_JavaBeans
>>
>> Thanks,
>>
>> Stefan
>> /
>
>
>
Re: access a BLOB coloumn from a CMP EJB
Posted by Jeremy Boynes <jb...@apache.org>.
It is probably simplest if we add byte[] as a mapped type inside TranQL
as that will result in the bytes being written to the LOB rather than
having it serialize an array object. I will try to add that mapping over
the weekend.
Having said that, the Serializable converter should work if you are
inserting the LOB using the EJB (and not directly through JDBC). The
stack you sent is from when we decided to roll the transaction back,
there should be another stacktrace in the log showing the true root
cause - can you post that one please.
--
Jeremy
Stefan Schmidt wrote:
> Hi,
>
> I am trying to access a (MySQL) MEDIUMBLOB coloumn from a CMP EJB. There
> are some tips @ Wiki but I still can't figure it out.
>
> Here are my artefacts:
>
> openejb-jar.xml:
>
> <cmp-field-mapping>
> <cmp-field-name>image</cmp-field-name>
> <table-column>image</table-column>
> <sql-type>BLOB</sql-type>
>
> <type-converter>org.tranql.sql.typeconverter.SerializableConverter</type-converter>
>
> </cmp-field-mapping>
>
>
> CMP EJB fields:
>
> public byte[] getImage();
>
> public void setImage(byte[] image);
>
>
> When trying to access this coloumn from my Session EJB :
>
> book.getImage();
>
> I get:
>
> javax.transaction.TransactionRolledbackException: Unable to load data
> for field
> at
> org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:126)
>
> at
> org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
>
> at
> org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82)
>
> at org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:234)
> at
> org.openejb.proxy.EJBMethodInterceptor.intercept(EJBMethodInterceptor.java:129)
>
> at
> org.openejb.proxy.EntityEJBObject$$EnhancerByCGLIB$$227af363.getImage(<generated>)
>
> at com.ibm.dw.bookshop.ejb.BookShopBean.getBooks(BookShopBean.java:135)
> ...
>
> Do I have to write my own /Type**Converter to get it right?
>
> Could anyone provide a short example on this (preferably write it on the
> wiki so everyone can see it)?
>
> The wiki link:
> http://wiki.apache.org/geronimo/Working_with_Enterprise_JavaBeans
>
> Thanks,
>
> Stefan
> /