simple singularities

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..

AjaxAnywhere, Great Java Based Ajax Solution

Filed under: java,programming — fri13th April 21, 2007 @ 5:29 pm

it’s just an amazing to see what AjaxAnywhere can do. it provides ajax-based page refresh function without any kind of pain. just cool!

though you have to add some javascript code for manipulation and automatic refresh, it’s not a big deal.

just like this.

<aa:zone name="yourTable">
<!– displaytag here –>
</aa:zone>

<script src="scripts/aa.js"></script>
<script type="text/javascript">
    ajaxAnywhere.getZonesToReaload = function() { return "yourTable" }
    function reloadAjaxAnywhere () {
        ajaxAnywhere.getAJAX(location.href, ‘yourTable’);
        window.setTimeout("reloadAjaxAnywhere()", 60000);
    }
    reloadAjaxAnywhere();
</script>

that’s all!

it may take some time to install AjaxAnywhere in your project.

1. add jar from maven repository
2. add aa.js to script folder manually. i get it from jar file.
3. add taglib like this
<%@ taglib uri="http://ajaxanywhere.sourceforge.net/" prefix="aa" %>

good luck!

sample pages
http://ajaxanywhere.sourceforge.net/
http://raibledesigns.com/rd/entry/the_future_of_the_displaytag

AjaxAnywhere는 displaytag를 ajax로 갱신하는 방법을 찾다가 발견한 라이브러리입니다. 주요한 기능은 refresh없이 페이지의 내용을 갱신하는 것입니다. 사실 이 기능말고는 지원하는게 없습니다. 하지만 써보면 딱 그 정도가 적당하다는 느낌입니다. 다른 기능은 DWR같은 걸로 구현하면 되니까요. 이런게 오픈소스 커뮤니티의 힘이겠지요. 뭔가 필요하다고 느낄때 누군가가 이미 작업을 해놓았다는걸 알면 개발자로서 굉장히 안도감이 듭니다.

몇번을 확인해보고 displaytag로는 아마도 ajax가 불가능하리라 생각했는데, 이 라이브러리를 써보니 그렇지 않다는 것을 알았습니다. 세상은 넓고 신기한 자바 라이브러리는 많더군요. 정기적으로 mvnrepository를 뒤져볼 필요가 있을 듯합니다.

더 자세한 정보는 링크한 페이지를 확인해보시길..

is there anything greater than framework?

Filed under: java,programming — fri13th April 10, 2007 @ 4:48 pm

probably most critical issue in framework is "reinvent-all" situation.  framework makes many things easy, but  if there’s something you want and it doesn’t supported by framework, you have to re-invent your own framework. it’ painful and more expensive than not using framework. and the world is filled with full of that kind of cases. sucks.. actually that’s the reason i sufferd every day.

no one care about the extreme case i faced now that gives more opportunity and earns more money. i may appreciate it, but not so fun, it’s just painful. so that reason, there will be no next thing than framework. everybody doesn’t want to be unhappy more than now.

do not depend on, do not compromise with framework. let framework do less. remember always, programmers can do more.

clean and tdd

Filed under: java,programming — fri13th April 5, 2007 @ 9:41 pm

today i faced an error like this:
org.apache.jasper.JasperException: …

and there was no appropriate error message at all.

i cleaned up and changed some spring settings in applicationContext.xml and finally i got reasonable error message

org.apache.jasper.JasperException: PWC6033: Unable to compile class for JSP
PWC6197: An error occurred at line: 3 in the jsp file: /common/header.jsp

it’s because i changed some class’s name and my trustable ide and compiler can’t check sanity of jsp file which contains java code. i know it’s not a good practice, but it’s very handy even in this mvc world.

there are two lessons here. clean is a good solution in compile language like reboot in window. you must be careful and don’t hasitate using tdd when you need rapid development.

dbhelper

Filed under: java,programming — fri13th April 3, 2007 @ 12:15 pm

dbhelper plugin in intellij idea is very useful, you can manage alomost every sql db in gui console. but when setting h2databse,  you have to turn off  "use full object name" option. check below link for further informations

http://ca.geocities.com/davidhuo2003/dbhelper/userguide.htm

 

appfuse small tip 2

Filed under: java,programming — fri13th March 23, 2007 @ 7:11 pm

it’s for new bee, like me

1. current h2 database’s version is 1.0.20061217, you can upgrade it to 1.0.20070304
2. there’s a bug in ehcache with embedded database.. it is appeared when test. this is not fixed yet..

and it’s only my opinion that hibernate and spring’s setting violate DRY rule. you have to register  same object twice.. i’ll anticipate better version..

P.S. i found that ehcache and spring configuration problems are fixed in new appfuse 2.0 M4. good job!

appfuse small tip

Filed under: java,programming,web2.0 — fri13th March 22, 2007 @ 1:27 pm

or just records for not to forget.

1. i change to use h2 as an embedded db rather than derby.. h2 is implemented more clear way(i think this is because of its predecessor, hsqldb) and supported in appfuse. it works fine for me with no error. so goodbye derby for a while~

2. sometimes you may get some mysterious compile errors when using ide. mvn updates libraries automatically but not ide’s setting at  the same time. you have to update your ide setting by manually. like this mvn idea:idea

3. i think intellij idea is better than eclipse. especially annotation support.

4. i extend default user class, org.appfuse.model.User somewhat awkard way.. i made another User Class and set its table name as app_user. it seems that works right. but i can’t be sure about all operations..

and more..

appfuse + derby part.1

Filed under: java,programming — fri13th March 5, 2007 @ 10:42 am

why appfuse & derby is important? because you can make an excellent embedded java web solution with them. why not other db? h2 is windows only. hsqldb has a critical bug, it shows error and stop working when accessing db data which size is larger than available memory. oracle berkeley db doesn’t support JPA. so only open-source solution is appfuse and derby.

at now, you can’t use embedded feature of derby. derby’s embedded mode allows only one access, and it makes things difficult to debug in ide. if there’s any solution, please let me know. when you test some, if you see this error "The userCache Cache is not alive" it’s because derbyclient.jar is not inside of project’s default library directory. i try to find some cool solutions but it maybe faster to wait next version of appfuse thant to solve myself.

probably there’s more issues  than  i’ve  faced. yesterday i stucked some error about applicationContext.xml’s manager feature. no appropriate error message was showed, and it made me ache.. i think there seems to be no choice but go on.. fighting..

<<< Previous Page - Next Page >>>