Bookmark and Share

Support wikipedia as I did

Wikipedia Affiliate Button

domenica, dicembre 28, 2008

BLOB type in MySQL

I had this exception when I was trying to insert a big image in a BLOB column using MySQL.

java.sql.BatchUpdateException: Data truncation: Data too long for column 'picture' at row 1


The problem didn't happen with small images, i.e. with the size of 2,3Kb. After spent some time to investigate about the problem, I understood that the reason is due to the BLOB type in MySQL whose maximum size is 64k. Therefore if you want to store big binary data in a MySQL database you need to use another blob type as MEDIUMBLOB or LONGBLOB.
If you are using JPA annotations to define your tables you need to specify the length of your BLOB attribute using the @Column annotation.
Here is what I have defined for the picture attribute used in jugevents application.

@Lob
@Basic(fetch = FetchType.LAZY)
@Column(length=1048576)
public byte[] getPicture() {
return picture;
}

In this way the type of the column corresponding to the picture attribute will be MEDIUMBLOB instead of BLOB and you won't get that exception

venerdì, dicembre 19, 2008

Cost of life in Dublin

The price of restaurants in Dublin is really high and the quality of food is really bad, at least if compare to Italy. It doesn't make sense to spend such a lot of money to eat chicken or potatoes. I don't know how's going this country...they are in recession, the number of unemployed people is getting high, but the shops and the restaurants don't want to cut the price. I realize last week end when I was in Venice how much cheaper are the price over there, I went to panorama supermarket in Marghera, I bought many items and I was amazed to have spent only 13 eur, in this fucking tesco at Stillorgan I would have spend for the same things at least 20 eur.
I mean...pay attention when you hear about salary in Ireland, even if it's true that the taxes are lower the cost of life is so fucking expansive over here...and you have to bear on mind that you don't have extra monthly salary like 13th or 14th and you don't even have TFR. You have to pay for your food at work, when in Italy you have ticket restaurants or free canteen. And, last but non least you have to apply for your schema pension, and it means another deduction of 3 to 4 % by your gross salary.

venerdì, dicembre 12, 2008

The Day the Earth Stood Still


Just a warning, if you are thinking about watching this movie, please don't do that, it's bullshit. I have had enough of all these American action movies, all of them are equals, the plot is the same, seen one it's like to have seen all of them. The features of the plot are:



  • An imminent attack to the World.
  • I don't know why the main attack will be in America, but not in the middle of nowhere, but in New York or Washington.
  • The US Army is involved, the president of the US is somewhere, safe in a secret place.
  • There are images from all over the world, poor people from Africa, the Pope in Rome, all united against the enemy of the Hearth.
  • There is a beautiful smart single woman, this time scientist...what a lucky so pretty so intelligent so young, only in the movies could happen...
  • Only one man could save the World, all the weapons of the US army can't do nothing, but a man.
  • The World is saved everyone is happy.

If you have seen Independence Day, The Day After Tomorrow, Armageddon, Gozilla, well it's almost the same.
Well stop with this kind of American action movies maybe now it's clear why most of the American are so stupid and fat...

giovedì, dicembre 11, 2008

Blackcat is back

It was ages I didn't see blackcat and the other black and white cat, so that I was thinking something bad was happened to them. To be honest in the last month I often was out in the night and probably they, tired to uselessly waiting for me, have started to lookup some other humans available to give them food. But today, as I am off at home, I saw, around midday, blackcat coming slowly to my window and I was nicely pleased about that. I still had a jar of kitcat, food for cats, so I gave it to him and he started to eat with pleasure. I am so happy to feed the cat, blackcat my beautiful black tomcat, with the green eyes. Maybe at this point you are wondering where is the other cat, juventus cat. I don't know, and I was hoping to meet him soon, but so far any news. I asked to blackcat where he could be, but he didn't answer to me, maybe because we don't speak the same language, or maybe because he only speaks Irish, that is, Gaelic. Unfortunately I am not still able to talk the cat's language...if it does exist.

lunedì, dicembre 08, 2008

Saving mode

Who said that in order to enjoy and to have a great life you need to spend a lot of money? Well actually I think it's bullshit. Saturday I was out with my dear Italian friend Giovanni, I had good time and I didn't spend such a lot of money. I got the bus to go to the city centre, after we had a delicious kebab with drink in a Persian restaurant in temple bar and it was quite cheap. Later we went in a typical Irish pub full of nice people and I paid for two cokes only 6 eur. When we left the pub was late so that there weren't bus to return to Stillorgan. I could take a cab spending 14 eur but I had preferred waiting for the first race of the nite-link that it cost to me only 5 eur. I remember other time when I was to cafe en saine where the drinks are rather expansive and I used to pay drink to the girls, again, I used to return home by cab. No that time is finished.
After a talk with my dear friend marcello, I have understood I need to save money if I want to have something solid for the time I'll be old. He said that because how much I have earned in the last 9 years I should have two loft in Milan...Well that's true even if my salary is not so big, just a normal salary as software engineer. Anyway I have realized that I have dissipated such a lot of money since when I started to work. Another thing I want to stop to do is spending money in expansive restaurants in Dublin. I am scared about this recession, everyone could lose the job in one day so I feel I need to save money. I mean I don't want to be tight but I am really upset after spent 40 eur to eat in a restaurant, does it make sense?
I used to pay even with most of my female friends but I think that time is finished, why should I pay drinks even if we are only friends? Well maybe I could lose some friends in this new phase of my life but maybe they weren't really friends.

venerdì, dicembre 05, 2008

Auto injected spring beans

A colleague of mine asked me to solve a problem about using beans, configured using the spring container, in legacy code.
Basically he couldn't change the way those beans are created but he wanted to be able to inject their properties using a spring configuration file.
This is the way he wants to create an instance of the class BeanAutoInjecting.

BeanAutoInjecting bai = new BeanAutoInjecting();

The class BeanAutoInjecting has its attributes injected by spring container but we don't want to have any trace of Spring in the code that use this class.
A friend of mine, Lucio, proposed me to use the class AutowiredAnnotationBeanPostProcessor to sort out this problem.
Therefore we have to modify the constructor of the class BeanAutoInjecting in this way:

public BeanAutoInjecting()
{
ApplicationContext ctx = SpringLoader.getApplicationContext();
AutowiredAnnotationBeanPostProcessor aabpp = (AutowiredAnnotationBeanPostProcessor)ctx.getBean(
"org.springframework.context.annotation.
internalAutowiredAnnotationProcessor");
aabpp.processInjection(this);
}

The trick is to define a dummy constructor and to instruct the spring container to use it. Here the dummy constructor

public BeanAutoInjecting(int a)
{
System.out.println("I am the dummy constructor!");
}

Here the definition of the bean and the auto-wiring directive in the spring configuration file.

<!-- auto wiring directive -->
<context:component-scan base-package="spikes.springexamples"/>
---------------------------
<!-- bean definition with dummy constructor ->
<bean name="beanAutoInjecting" class="spikes.springexamples.BeanAutoInjecting">
<constructor-arg>15</constructor-arg>
</bean>

That's cool I would say, I am able to use a spring managed bean in my legacy code creating it out of the spring container!!!

mercoledì, dicembre 03, 2008

Exception from radio deejay podcast


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.jsp.JspException: An exception occured trying to convert String "3.117.056" to type "java.lang.Double"
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.juseppe.JuseppeFilter.dispatchRequest(JuseppeFilter.java:774)
org.juseppe.JuseppeFilter.doFilter(JuseppeFilter.java:693)
org.ft.servlet.filters.httpheaders.HTTPHeadersFilter.doFilter(HTTPHeadersFilter.java:162)

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: An exception occured trying to convert String "3.117.056" to type "java.lang.Double"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:854)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.pages.podcast.channel_jsp._jspService(org.apache.jsp.pages.podcast.channel_jsp:619)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.juseppe.JuseppeFilter.dispatchRequest(JuseppeFilter.java:774)
org.juseppe.JuseppeFilter.doFilter(JuseppeFilter.java:693)
org.ft.servlet.filters.httpheaders.HTTPHeadersFilter.doFilter(HTTPHeadersFilter.java:162)

root cause

javax.servlet.jsp.el.ELException: An exception occured trying to convert String "3.117.056" to type "java.lang.Double"
org.apache.commons.el.Logger.logError(Logger.java:481)
org.apache.commons.el.Logger.logError(Logger.java:498)
org.apache.commons.el.Logger.logError(Logger.java:566)
org.apache.commons.el.Coercions.coerceToPrimitiveNumber(Coercions.java:440)
org.apache.commons.el.DivideOperator.apply(DivideOperator.java:144)
org.apache.commons.el.BinaryOperatorExpression.evaluate(BinaryOperatorExpression.java:170)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:932)
org.apache.jsp.pages.podcast.channel_jsp._jspx_meth_fmt_parseNumber_1(org.apache.jsp.pages.podcast.channel_jsp:12143)
org.apache.jsp.pages.podcast.channel_jsp._jspx_meth_x_forEach_1(org.apache.jsp.pages.podcast.channel_jsp:11877)
org.apache.jsp.pages.podcast.channel_jsp._jspx_meth_x_when_1(org.apache.jsp.pages.podcast.channel_jsp:11710)
org.apache.jsp.pages.podcast.channel_jsp._jspx_meth_x_choose_1(org.apache.jsp.pages.podcast.channel_jsp:11670)
org.apache.jsp.pages.podcast.channel_jsp.access$2(org.apache.jsp.pages.podcast.channel_jsp:11659)
org.apache.jsp.pages.podcast.channel_jsp$channel_jspHelper.invoke2(org.apache.jsp.pages.podcast.channel_jsp:12986)
org.apache.jsp.pages.podcast.channel_jsp$channel_jspHelper.invoke(org.apache.jsp.pages.podcast.channel_jsp:13008)
org.apache.jsp.tag.meta.invoke_tagx._jspx_meth_c_if_2(org.apache.jsp.tag.meta.invoke_tagx:392)
org.apache.jsp.tag.meta.invoke_tagx.doTag(org.apache.jsp.tag.meta.invoke_tagx:298)
org.apache.jsp.pages.podcast.channel_jsp._jspService(org.apache.jsp.pages.podcast.channel_jsp:490)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.juseppe.JuseppeFilter.dispatchRequest(JuseppeFilter.java:774)
org.juseppe.JuseppeFilter.doFilter(JuseppeFilter.java:693)
org.ft.servlet.filters.httpheaders.HTTPHeadersFilter.doFilter(HTTPHeadersFilter.java:162)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.