These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: Using Blob gives an IllegalArgumentException
PostPosted: Wed Aug 31, 2005 10:44 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Hibernate version: 3.0

Hello everyone,

First of all, I'm a newbie, so keep it in mind please.

I'm trying to use a blob field, but with no sucess. I read about it and I know there are some issues for Oracle, but I'm using Firebird 1.5 so AFAIK there are no issues, right?

Here's what happens... I have an action that would insert a value in a table. But when it's called, I get this error:

Code:
exception

javax.servlet.ServletException: BeanUtils.populate
   org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
   org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

root cause

java.lang.IllegalArgumentException: Cannot invoke auge.form.AddDelUpdCorForm.setDescricao - argument type mismatch
   org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778)
   org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)
   org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
   org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
   org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
   org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
   org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
   org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
   org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


As you see, it says I have a argument type mismatch in my setDescricao method, which is in my bean. My bean is as follows:

Code:
package auge.bean;

import java.sql.Blob;
import java.io.Serializable;
public class Cor implements Serializable {

   private String cor;
   private String nome;
   private Blob descricao;

        public Cor(){
        }
       
   public String getCor() {
      return this.cor;
   }
   
   public String getNome() {
      return this.nome;
   }
   
   public Blob getDescricao() {
      return this.descricao;
   }
   
   public void setCor(String cor) {
            this.cor = cor;
   }
   
   public void setNome(String nome) {
            this.nome = nome;
   }
   
   public void setDescricao(Blob descricao) {
            this.descricao = descricao;
   }
}


At last, my hbm.xml is as follows:

Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <class name="auge.bean.Cor" table="CORES" >
          <id name="cor" column="cor" type="java.lang.String">
              <generator class="assigned"/>
          </id>
       <property name="nome" column="nome" type="java.lang.String" />         
       <property name="descricao" column="descricao" type="blob" />
    </class>
</hibernate-mapping>


What I'm trying to insert into this blob is a normal String. No images or anything fancy.

Am I doing the wrong way? Is there anything misplaced in my code?

Thank you all very much


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 12:28 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 12:33 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
In your mapping file, use this:

<property name="descricao" column="descricao" type="java.sql.Blob" />

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 12:46 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
I forgot to mention, I tried that already... it makes no difference

I'm putting here another part of my log, which may tell something:

Code:
2005-08-31 13:46:38,732 DEBUG struts.action.RequestProcessor  ->  Populating bean properties from this request
2005-08-31 13:46:38,733 DEBUG commons.beanutils.BeanUtils  -> BeanUtils.populate(auge.form.AddDelUpdCorForm@1e55794, {nome=[Ljava.lang.String;@1d8d237, cor=[Ljava.lang.String;@1d13272, descricao=[Ljava.lang.String;@146e381})
2005-08-31 13:46:38,734 DEBUG commons.beanutils.BeanUtils  ->   setProperty(auge.form.AddDelUpdCorForm@1e55794, nome, [10])
2005-08-31 13:46:38,734 DEBUG commons.beanutils.ConvertUtils  -> Convert string '10' to class 'java.lang.String'
2005-08-31 13:46:38,734 DEBUG commons.beanutils.ConvertUtils  ->   Using converter org.apache.commons.beanutils.converters.StringConverter@f894ce
2005-08-31 13:46:38,734 DEBUG commons.beanutils.PropertyUtils  -> setSimpleProperty: Invoking method public void auge.form.AddDelUpdCorForm.setNome(java.lang.String) with value 10 (class java.lang.String)
2005-08-31 13:46:38,734 DEBUG commons.beanutils.BeanUtils  ->   setProperty(auge.form.AddDelUpdCorForm@1e55794, cor, [10])
2005-08-31 13:46:38,734 DEBUG commons.beanutils.ConvertUtils  -> Convert string '10' to class 'java.lang.String'
2005-08-31 13:46:38,734 DEBUG commons.beanutils.ConvertUtils  ->   Using converter org.apache.commons.beanutils.converters.StringConverter@f894ce
2005-08-31 13:46:38,734 DEBUG commons.beanutils.PropertyUtils  -> setSimpleProperty: Invoking method public void auge.form.AddDelUpdCorForm.setCor(java.lang.String) with value 10 (class java.lang.String)
2005-08-31 13:46:38,734 DEBUG commons.beanutils.BeanUtils  ->   setProperty(auge.form.AddDelUpdCorForm@1e55794, descricao, [10])
2005-08-31 13:46:38,734 DEBUG commons.beanutils.ConvertUtils  -> Convert string '10' to class 'java.sql.Blob'
2005-08-31 13:46:38,734 DEBUG commons.beanutils.ConvertUtils  ->   Using converter org.apache.commons.beanutils.converters.StringConverter@f894ce
2005-08-31 13:46:38,734 DEBUG commons.beanutils.PropertyUtils  -> setSimpleProperty: Invoking method public void auge.form.AddDelUpdCorForm.setDescricao(java.sql.Blob) with value 10 (class java.lang.String)
2005-08-31 13:46:38,804 ERROR commons.beanutils.PropertyUtils  -> Method invocation failed.
java.lang.IllegalArgumentException: argument type mismatch


See? It doesn't seem to make any conversion from the String I entered in the form to the Blob. Although it calls the StringConverter, it invokes the method setDescricao passing a String and not a Blob.

Do I have to do any kind of conversion? Are my getters and setters correct?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 12:47 pm 
Newbie

Joined: Wed Aug 31, 2005 11:20 am
Posts: 13
Have you tried using a byte array. We have a Blob in one of our classes here and we manage it with a byte[].

Here is what it looks like in our class :

@Column(name="USRP_data")
@Lob(type=LobType.BLOB)
public byte[] getData()
{
return data;
}

public void setData(byte[] data)
{
this.data = data;
}

Hope this help you out.

Francois Archambault


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 1:18 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
I did it, but still nothing happened. Here are my getters and setters:

Code:
   private byte[] descricao;
   
   public byte[] getDescricao() {
      return this.descricao;
   }
   
   public void setDescricao(byte[] descricao) {
            this.descricao = descricao;
           
   }


as you see, I declared it as byte and not as Blob. Now my question is: how should it be mapped in the hbm.xml? 'cause although I changed it to byte in the bean, the mapping file still carries "java.sql.Blob", which may be causing the error.

Here's how I access it:

Code:
                    cor.setDescricao(addCorForm.getDescricao()
                                               .getBytes(Long.valueOf("1").longValue(),
                                                (int) addCorForm.getDescricao().length()));


Thank you very much...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 1:31 pm 
Newbie

Joined: Wed Aug 31, 2005 11:20 am
Posts: 13
What if you change your mapping for this :

<property name="descricao" column="descricao" type="blob" />


What data type is your database field for descricao ?

Do you still have the same error (argument type mismatch) ?

Francois Archambault


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 1:58 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
I'm SO sorry. I made the hugest confusion changing things on my bean and forgeting them on my form. Now that I got this clear, I see that your great tip almost solved my problem.

Apparently now it accepts my getters and setters well, but maybe my values aren't being correctly getted and setted.

That's what I got in my log now:

Code:
2005-08-31 14:49:16,647 DEBUG event.def.AbstractSaveEventListener  -> saving [auge.bean.Cor#15]
2005-08-31 14:49:16,744 DEBUG event.def.AbstractFlushingEventListener  -> flushing session
2005-08-31 14:49:16,745 DEBUG event.def.AbstractFlushingEventListener  -> processing flush-time cascades
2005-08-31 14:49:16,748 DEBUG event.def.AbstractFlushingEventListener  -> dirty checking collections
2005-08-31 14:49:16,748 DEBUG event.def.AbstractFlushingEventListener  -> Flushing entities and processing referenced collections
2005-08-31 14:49:16,755 DEBUG event.def.AbstractFlushingEventListener  -> Processing unreferenced collections
2005-08-31 14:49:16,756 DEBUG event.def.AbstractFlushingEventListener  -> Scheduling collection removes/(re)creates/updates
2005-08-31 14:49:16,756 DEBUG event.def.AbstractFlushingEventListener  -> Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2005-08-31 14:49:16,756 DEBUG event.def.AbstractFlushingEventListener  -> Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2005-08-31 14:49:16,756 DEBUG hibernate.pretty.Printer  -> listing entities:
2005-08-31 14:49:16,757 DEBUG hibernate.pretty.Printer  -> auge.bean.Cor{nome=15, cor=15, descricao=[B@1c39412}
2005-08-31 14:49:16,757 DEBUG event.def.AbstractFlushingEventListener  -> executing flush
2005-08-31 14:49:16,760 DEBUG persister.entity.BasicEntityPersister  -> Inserting entity: [auge.bean.Cor#15]
2005-08-31 14:49:16,760 DEBUG hibernate.jdbc.AbstractBatcher  -> about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-08-31 14:49:16,760 DEBUG org.hibernate.SQL  -> insert into CORES (nome, descricao, cor) values (?, ?, ?)
Hibernate: insert into CORES (nome, descricao, cor) values (?, ?, ?)
2005-08-31 14:49:16,761 DEBUG hibernate.jdbc.AbstractBatcher  -> preparing statement
2005-08-31 14:49:16,767 DEBUG hibernate.jdbc.ConnectionManager  -> running Session.finalize()
2005-08-31 14:49:16,788 DEBUG persister.entity.BasicEntityPersister  -> Dehydrating entity: [auge.bean.Cor#15]
2005-08-31 14:49:16,788 DEBUG hibernate.type.StringType  -> binding '15' to parameter: 1
2005-08-31 14:49:16,811 DEBUG hibernate.impl.SessionImpl  -> closing session
2005-08-31 14:49:16,811 DEBUG hibernate.jdbc.ConnectionManager  -> closing JDBC connection [ (open PreparedStatements: 1, globally: 1) (open ResultSets: 0, globally: 0)]
2005-08-31 14:49:16,813 DEBUG struts.tiles.TilesRequestProcessor  -> processForwardConfig(/pages/erro.jsp, false)


As you see, it doesn't clearly shows me any errors, but an error happens. The insert doesn't work.

My column type is BLOB SUBTYPE 0. The property is now mapped the way you said.

Thanks very much, you're really helping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 2:12 pm 
Newbie

Joined: Wed Aug 31, 2005 11:20 am
Posts: 13
Can you show me how you persist your "Cor" ?

Does your Cor instance really contains everything it needs before persisting ?

Is there something like the Profiler for Microsoft SQL Server but for Firebird, if so, you should try to see what is the exact query sent to the database server. If I check your DEBUG, it seems like only the 1st parameter has his value sets.

2005-08-31 14:49:16,788 DEBUG hibernate.type.StringType -> binding '15' to parameter: 1
2005-08-31 14:49:16,811 DEBUG hibernate.impl.SessionImpl -> closing session

Francois Archambault


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 2:18 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
precisely! it binds the value only to the first parameter and it closes session before time!

about Profiler, what does it do? I don't know it.

Here's how I'm persisting:

Code:
            cor = new Cor();
            try {
                cor.setCor(addCorForm.getCor());
                cor.setNome(addCorForm.getNome());
                cor.setDescricao(addCorForm.getDescricao());
                CorService.getInstance().addCor(cor);
                return mapping.findForward("success");
            } catch (Exception e) {
                return mapping.findForward("error");


as you see, I only call the "addCor" method after passing the values. And if you look upper in the log, you'll see:

Code:
2005-08-31 14:49:16,756 DEBUG event.def.AbstractFlushingEventListener  -> Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2005-08-31 14:49:16,756 DEBUG event.def.AbstractFlushingEventListener  -> Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2005-08-31 14:49:16,756 DEBUG hibernate.pretty.Printer  -> listing entities:
2005-08-31 14:49:16,757 DEBUG hibernate.pretty.Printer  -> auge.bean.Cor{nome=15, cor=15, descricao=[B@1c39412}


So, it does pass the value at a time, right?

my addCor method is:

Code:
   public void addCor(Cor cor) throws HibernateException
   {
      Session session = ConnectionFactory.getInstance().getSession();
      Transaction t = null;
               
      try
      {
                        t = session.beginTransaction();
         session.save(cor);
         session.flush();
         t.commit();                       
      }
      catch (HibernateException he)
      {
                        if (t != null) {
                            t.rollback();
                        }
         throw he;
      }
      finally
      {
         if (session != null)
         {
            try
            {
               session.close();
            }
            catch (HibernateException e)
            {
               System.err.println("Hibernate Exception" + e.getMessage());
               throw new RuntimeException(e);
            }
         }
      }
   }

I have an equal method for other classes and it works perfectly. The difference between this and the others is the byte thing.

What could be causing the values to lose themselves?

Thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 2:31 pm 
Newbie

Joined: Wed Aug 31, 2005 11:20 am
Posts: 13
You should try to set a breakpoint on session.save and check if your cor instance actually contains everything you need, if it does, than the problem is in the session.save method somewhere. Maybe you should try saveOrUpdate ?

Elseway, you should trace and see when your byte array is lost.

Francois Archambault


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 3:16 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
It's not possible to debug "save", since when I do a "step into" it, nothing happens. Tried "saveOrUpdate" too, same thing.

The funny thing I observed here is that when I enter less than 3 digits in the field, it gives me the error I said in the post above. If I enter more than 3 digits, I'll get a DataTruncation.

Well I'll just keep trying. Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 3:20 pm 
Newbie

Joined: Wed Aug 31, 2005 11:20 am
Posts: 13
How come is it not possible for you to debug "save" ? Can you at least set a System.out.println to check if data are still there ? Are you using JBoss or another application server ? If so, there is probably a serialization problem.

Check this out.

Francois Archambault


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.