simple singularities

NullPointerException in Struts 2

Filed under: java, programming — fri13th December 12, 2007 @ 5:17 pm

i stuck some strange bug today. somewhat wierd error message showed when i tried to login with unauthorized account. it’s only a 403 situation. why i have to see this error messages?

java.lang.NullPointerException
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58)
org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport .java:54)
org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport .java:49)
org.apache.jsp.WebContent.index_jsp._jspx_meth_s_005fhead_005f0(index_jsp.java: 155)
org.apache.jsp.WebContent.index_jsp._jspService(index_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

at first, i thought it’s the problem of authentification. but that wasn’t. it’s because i use struts 2’s <s:if tag in my header.jsp. struts 2’s tags cannot be used in jsp directly. you have to use those with some actions. so my 403.jsp generates an error message for that. i change it to <c: and it works fine now.

struts 2 validation

Filed under: java — fri13th December 11, 2007 @ 6:10 pm

i always wonder why struts 2 doesn’t provide well-made validation documents. and now i find that’s because there are well-made documents already. search opensymphony site not apache site. apache just give a hint about struts 2.

now i can do much better with struts 2. (am i too late?)

http://www.opensymphony.com/xwork/wikidocs/Validation%20Framework.html

P.S. Oh, i found real struts 2 validation page. why i can’t get it till now.. mysterious..
http://struts.apache.org/2.x/docs/validation.html

h2 database Unique index or primary key violation

Filed under: java, programming — fri13th November 19, 2007 @ 2:15 pm

h2 is a cool java sql db. it’s quick and handy. but not stable as other (non-java) db solutions.

sometimes “Unique index or primary key violation” is occured. probably inserting data in multiple threads cause this (though i set single thread mode). it’s critical, you have to fix this manually, not automatically.

in h2’s official site, this procedure is not well explained. org.h2.tools.Recover and org.h2.tools.RunScript will fix this problem.

1. org.h2.tools.Recover will generate *.sql backup file.
2. delete broken db
3. run org.h2.tools.RunScript. you will face some sql error.
4. comment the parts in *.sql. delete db and run RunScript again and again.

if you have a critical data, you have to be careful to fix sql file.

i’m testing h2 database’s memory usage.. it costs too much memory when indexing tables.. i have to choose between search performace and memory usage.. good luck to me~

mysterious and unlucky debugging on h2 database

Filed under: java, programming — fri13th September 4, 2007 @ 2:11 pm

i faced some serious issues in h2 database, the h2 data saved in local file system are disapeared whenever tomcat is restarted only in window mode. i found easily that this problem is based on the db url parameter.

like this:
LOCK_MODE=0;LOG=0;MULTI_THREADED=1;DEFAULT_TABLE_TYPE=MEMORY;RECOVER=1;
ASSERT=0;CACHE_SIZE=200000;DEFAULT_LOCK_TIMEOUT=5000;TRACE_LEVEL_SYSTEM_OUT=0;
TRACE_LEVEL_FILE=0;LOCK_TIMEOUT=5000;

it’s tuned for fastest speed. and you know debugging is always a matter of choice. i choosed most suspicious options first. and test and test. but i can’t found till there left only one option, LOG=0, and finally i remove it, the program works so smoothly with no error..

i spend almost 2 hours for this simple test which would be ended in 10 mins. i know i’m an unlucky guy, i always have been. it will not be overcome soon..

h2 and embedded java sql file db

Filed under: java, programming — fri13th July 5, 2007 @ 11:20 am

i have to admit there’s no good embedded java sql file db actually. i tested h2 yesterday and  h2 was good before the tuple was over 20,000. db access speed is scaled by O(n). and it showed heap error finally. aside the deadly critical table lock problem in concurrent situation, it cannot be used for real world db solution.

i know h2 is very good db, fastest and easy to use(with hibernate). i was impressed much. but when i need some db for embedded log system, h2 is not the product i have to adopt.

so there’s 3 ways  to solve this problem.
1. use derby(is there any other file base sql java db?)
2. use berkeley db java edition, this is not sql base
3. use non-java sql file db

derby is too slow, and buggy.. berkeley db’s structure is very different  and i have to redesign the entire or at least half of application. i’m not sure what is a good non-java sql file db. and non-java solution is also hard to maintain with servlet solution. there’s no time, so i have to decide  asap.. good luck to me~

P.S. i found some good discussion about this topic
http://www.h2database.com/ipowerb/index.php?s=58737509ee010033b0743b7a55a6f957&showtopic=331&st=0&

it seems that postgresql is the best solution, though it’s not a java db. but, i may choose the 4th option. 4. find a way with h2 -_-;;

raible’s works - comparing java web framework

Filed under: java, programming — fri13th June 27, 2007 @ 11:59 am

it’s a good to know document.

http://raibledesigns.com/rd/entry/ja_sig_comparing_java_web

i’m using struts2 now.. it has many cool and useful features, but no satisfiable amount of docs and no intutive coding style, especially ognl.. struts 2 uses ognl heavily. but the official ognl doc for struts is like this. http://struts.apache.org/2.0.8/docs/ognl.html

i think there’s no definitively good (i may say, perfect) framework in java scene now.. the only way to survive is to sacrifice the functionalities, and you don’t need to hesitate for that kind of decisions..

strage situation in struts 2 redirection

Filed under: java, programming — fri13th June 25, 2007 @ 9:41 pm

i need to deliver some parameter when redirecting in struts 2. it’s some what like this..

Action.java
Long id;
public Long getId() {
 return this.id;
}

struts.xml
<action name="saveAction" class="Action" method="save">
     <result name="success" type="redirect">
        <param name="location">url.html?id=${id}</param>
        <param name="parse">true</param>
        <param name="encode">true</param>
      </result>
</action>

and it fairly doens’t work.. like this..
url.html?id=com.cns:ips:war:2.0

what the hell!

i change it to this

Action.java
Long myId;
public Long getMyId() {
 return this.myId;
}

struts.xml
<action name="saveAction" class="Action" method="save">
     <result name="success" type="redirect">
        <param name="location">url.html?id=${myId}</param>
        <param name="parse">true</param>
        <param name="encode">true</param>
      </result>
</action>

and it works fine! please tell me how redirect works in struts? if struts 2 uses id as a reserved variable.. why can i get those documents? there’s so many mystery in struts and java world..

hibernate default value

Filed under: java, programming — fri13th May 22, 2007 @ 11:09 am

i found some trouble in hibernate, last night. hibernate annotation doesn’t support default value explicitly. you can use by implementing UserType interface. but, you know it’s not an annotation at all. there’s two workarounds to avoid this situation. first is making tables and model classes manually. use alter or create you know, this isn’t annotation but it doesn’t conflict annotation nor clumsy. 2nd is columnDefinition. this is an annotation and non-portable way to definite table. i don’t want to recommend it, either.

i choosed the first, manual way to solve my problem. but it’s very unpleasant to use non-authentic way when implementing basic functions. hibernate supports so many sql dbs. for that reason, basically hibernate provides minimum set of functions. and when you want more, there’s no way but to use workarounds.. and you know, workarounds are not documented well.. it’s a some kind of tragic..

convention over configuration

Filed under: java, programming — fri13th May 11, 2007 @ 10:56 am

probably you have heard this phrase. it’s one of RoR’s main policies. though i like this concept, there’s some critical problem in it. if you don’t know convention, you can’t go further.. and only who accustomed to that environment knows convention well. convention is created from popular ideas, it is somewhat had to be. so there’s likely to be no good example or explanation for newbie who doesn’t know the atmosphere.

today i set log4j environment for mvn. i had to set log4j using configuration file. and i couldn’t find how and what to do..  i thought some, saw pom.xml, change some configuration that didn’t do nothing. and finally i copied  log4j.xml to src/main/resources and i knew that was all i had to do..

CoC is very convenience, i admit, but if i was a newbie i can’t find how to set log4j.. but anyway.. it goes like that.. the trend of programming will go to more esoteric way from now on, i think.

switching sql db’s data using dbunit

Filed under: java, programming — fri13th May 10, 2007 @ 9:37 pm

recently i search for data migration from mysql to h2. two dbs have different sql syntax
and at first i thought it’ll become a very hard job. but using dbunit, i can switch database
so easily and perfectly. this is very useful for any kind of sql db migration, not only mysql to h2.
oracle or postgresql or mssql or any db to any db else!

and the job is very simple and fast

just type this command
mvn dbunit:export
and you can see xml file with all data from db in target/dbunit/export.xml

next, change db setting in maven’s pom.xml or set db explicitly and load these data
mvn -Ph2 dbunit:operation

and that’s all, game over! and sorry, really it was not that easy..
there’s some problems in dbunit. dbunit doesn’t support foreign key.
so if there are two tables, address, zipcode and address refer zipcode,
you can’t input address first, you have to move it below zipcode.
and dbunit get data from alphabetical order, and put data sequentially
you have to care about this characteristic.

2nd one was more difficult to solve. dbunit gets data as an utf-8 text format
including non-compatible character, 0×00, i don’t know why. it’s obviously weird.
if there’s 0×00 you cannot insert data before you remove that character.
i know one editor that remove it automatically. it’s EmEditor! cool!
and you have nothing to do, just open and save as make things work!
maybe tr or something do the samething but i didn’t test  another  way.

3rd one was not caused by dbunit, it caused by db’s sql syntax, and hibernate.
varchar’s length or text type is different  little.  and mysql skips some unexplicit
annotation setting and other db doesn’t. e.g) you can set length=6
in hibernate annotation and save 7 char string in mysql, but it generate an error in h2.

and finally i succeeded to migrate! thanx god! i probably died if i had to change mysql sql syntax to h2’s..

dbunit is very cool stuff, but has some bugs.. i wish it’s next version will be solved these bugs..
but too slow to update.. i may participate dbunit’s improvement.. can i?.. um.. um..

Next Page >>>