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

FizzBuzz Problem

Filed under: programming, smalltalk — fri13th May 11, 2007 @ 1:01 pm

the famous FizzBuzz Problem.

this is my solution, it takes 5 min (if(!0) doesn’t work, so i have to use ==0, it takes about 3min), and i revise it in another 3 min to remove a temporary variable, and make code neat.

#!/usr/bin/perl
for $i (1..100) {
    print $i if $i%3&&$i%5;
    print "Fizz" if $i%3==0;
    print "Buzz" if $i%5==0;
    print "\n";
}
of course i can solve by using many other language.. but the basic is the same.. someone might save some character, but i don’t want to ruin the readablity nor main concept of algorithm.

http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/

P.S. i can remove two mod operations by using a temp varibale, but i can’t say it’s right or wrong..

P.P.S. i found more simple solution from internet.. this code is just what i imagine.. cool..
print(($_%3?"":Fizz).($_%5?"":Buzz)or$_) for(1..100)

convention over configuration

Filed under: java, programming — fri13th @ 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..