March 2007 - Posts
Ok, I almost gave up at my early attempt in learning Hibernate. I encountered the following errors
QuerySyntaxException - I accidentally mistook the table name to the class name.
List messages = newSession.createQuery("from TABLE m order by m.text asc").list();should be
List messages = newSession.createQuery("from CLASS m order by m.text asc").list();InstantiationException: No default constructor for entity... - Luckily this error was descriptive enough that I figured out the problem on my own. I just had to supply a "No-Argument Constructor"
Now I can go back to having fun learning Hibernate. Hopefully someone who's googling right now could find this post useful. :)
I've done it. You should too! Check this out:
http://www.netbeans.org/kb/55/persistence-demo.htmlHmmm... Now for me, there really is nothing that RoR can do that Java can't.
Sun is doing quite a great move in improving the netbeans IDE by creating a lot of interesting add-on on it. There's the mobility pack, profiler, and now the
Sun Web Developer Pack which includes a lot of technologies that you can use to ease your web development in Java. They're as follows
- AJAX Technologies
- Scripting
- REST-based services
Perhaps the thing that really caught my attention is the scripting feature and this
screencast I've seen here using jMaki.
As I was looking into these devpack, I wondered was has really changed in the netbeans IDE.
This link would give you a lot of information about what's changed. And although I use eclipse for most of my projects, Netbeans is giving a lot to me now. This is good news for me since we're about to use netbeans for our next project.
I was following a tutorial with Hibernate and one of the tools required for it is Ant. Most Java developers are aware (they should be) that most Java IDE they use ships with Ant including Eclipse and Netbeans. Ironically, as we are aware of this very few people care about really knowing these greate tools(ant, maven, etc.). And so, as every C/C++ developer should be aware or be knowledgeable of using make, I also took a stand that as a Java developer therefore I shold now Ant(or any similar tool for Java).
Along my way in the tutorial I mentioned, I dunno if it was the author's mistake but I was instructed to replace the batch files I built which looked like this BTW
1 2 3 4 | javac -classpath .\lib\hibernate3.jar -d bin src\wp\hibernate\test\*.java copy /Y src\hibernate.cfg.xml bin copy /Y src\wp\hibernate\test\*.xml bin\wp\hibernate\test copy /Y src\log4j.properties bin |
with an ant script. Here is an example but more things were added since I stopped using batch files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <project name="hibernate-test" default="compile">
<property name="sourcedir" value="${basedir}/src"/> <property name="targetdir" value="${basedir}/bin"/> <property name="libdir" value="${basedir}/lib"/> <property name="configdir" value="${basedir}/config"/> <property name="wardir" value="${basedir}/war"/> <property name="viewsdir" value="${basedir}/views"/> <property name="static-htmldir" value="${basedir}/static-web"/>
<target name="compile" depends="copy-resources">
<javac srcdir="${sourcedir}" destdir="${targetdir}" debug="on"> <classpath>
<fileset dir="${libdir}"> <include name="*.jar"/> </fileset>
</classpath> </javac>
</target>
<target name="copy-resources"> <copy todir="${targetdir}"> <fileset dir="${sourcedir}"> <exclude name="**/*.java"/> </fileset>
</copy>
</target>
<target name="setup-war-structure" depends="compile"> <mkdir dir="${wardir}"/> <mkdir dir="${wardir}/WEB-INF"/> <mkdir dir="${wardir}/WEB-INF/classes"/> <mkdir dir="${wardir}/WEB-INF/lib"/> <mkdir dir="${wardir}/WEB-INF/views"/>
<copy todir="${wardir}/WEB-INF/classes"> <fileset dir="${targetdir}"/> </copy>
<copy todir="${wardir}/WEB-INF/lib"> <fileset dir="${libdir}"/> </copy>
<copy todir="${wardir}/WEB-INF/views"> <fileset dir="${viewsdir}"/> </copy>
<copy todir="${wardir}/WEB-INF/"> <fileset dir="${configdir}"/> </copy>
<copy todir="${wardir}"> <fileset dir="${static-htmldir}"/> </copy>
</target>
</project> |
However, I had problems with the above script(I prefer to call it script). The setup-war-structure was not executing. I atleast had to sleep to figure out the problem.
As we can see, Ant executes a "chain of command". Atleast from what I understood. From the very first target you specified using the project tag's "default" attribute, it would then execute that specific target and all its dependencies.
From the above example, I instructed Ant to execute compile, but compile is dependent to the copy-resources target, thus it would execute copy-resources first before compile.
The fix I did was simple, I just changed the project's default attribute to "setup-war-structure". Therefore, setup-war-structure and all of its dependencies would be executed. In this case, it would execute in this order
copy-resources
compile (dependent to above)
setup-war-structure (dependent to above)
Here's the working build.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <project name="hibernate-test" default="setup-war-structure">
<property name="sourcedir" value="${basedir}/src"/> <property name="targetdir" value="${basedir}/bin"/> <property name="libdir" value="${basedir}/lib"/> <property name="configdir" value="${basedir}/config"/> <property name="wardir" value="${basedir}/war"/> <property name="viewsdir" value="${basedir}/views"/> <property name="static-htmldir" value="${basedir}/static-web"/>
<target name="compile" depends="copy-resources">
<javac srcdir="${sourcedir}" destdir="${targetdir}" debug="on"> <classpath>
<fileset dir="${libdir}"> <include name="*.jar"/> </fileset>
</classpath> </javac>
</target>
<target name="copy-resources"> <copy todir="${targetdir}"> <fileset dir="${sourcedir}"> <exclude name="**/*.java"/> </fileset>
</copy>
</target>
<target name="setup-war-structure" depends="compile"> <mkdir dir="${wardir}"/> <mkdir dir="${wardir}/WEB-INF"/> <mkdir dir="${wardir}/WEB-INF/classes"/> <mkdir dir="${wardir}/WEB-INF/lib"/> <mkdir dir="${wardir}/WEB-INF/views"/>
<copy todir="${wardir}/WEB-INF/classes"> <fileset dir="${targetdir}"/> </copy>
<copy todir="${wardir}/WEB-INF/lib"> <fileset dir="${libdir}"/> </copy>
<copy todir="${wardir}/WEB-INF/views"> <fileset dir="${viewsdir}"/> </copy>
<copy todir="${wardir}/WEB-INF/"> <fileset dir="${configdir}"/> </copy>
<copy todir="${wardir}"> <fileset dir="${static-htmldir}"/> </copy>
</target>
</project> |
Hmmm... Now I go to finish my reading. :)
It's too bad for me that we have this get-together party at our office on Friday. Some prominent people in the Java community is arranging a meeting and I badly want to attend because they will be discussing topics I've been so into these past few months. This is actually for pinoyjug members but Mr. Calen Legaspi said it's free for everyone.
Friday at 6:00pm at the office of Stratpoint Technologies. Stratpoint will be sponsoring pizza and drinks.
Venue:
Stratpoint Technologies
7F Net Square, 28th St. corner 3rd Ave.
Crescent Park West, Bonifacio Global City
Taguig City, Philippines 1634
Map: http://stratpoint. com/pdfs/ mapNet2.pdf
Talk #1: Spring IoC Framework
Speaker: Alistair Israel, Stratpoint Technologies
Talk #2: Hibernate ORM Framework
Speaker: JM Ibanez, Orange & Bronze Software Labs
Talk #3: SCJP 5 Certification
Speaker: Lawrence Decamora, Sun Microsystems PhilippinesAwwwww! Why did it have to be on Friday! Darn it!
Hmmm... So much for my struggle that even after having learned dynamic memory allocation it took me a couple of hours to figure this out. This may not be interesting for developers using .net or Java but atleast for students learning C/C++, it is. So how do you create an Array of char* or C strings? Here's a code snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | char** stringArray;
int maxWords = 3;
stringArray = new char*[maxWords];
stringArray[0] = "I"; stringArray[1] = " Love "; stringArray[2] = "C++";
for (int i = 0; i < maxWords; i++) { std::cout << stringArray ; } |
Now I'm no expert C programmer to explain all that stuff. It's pretty straightforward anyway. From the C++ programmer point of view, C strings should be avoided because they bring about adisaster in your program that is hard to debug. Still, they're fun to use in small-scale applications and it's mandatory that every C/C++ programmer learn how to use them.