Saturday, February 26, 2011

The project continues

I have to work on the project more and change certain things in my architecture and technologies. Here is the list of things that has to be done:
  • Separate presentation from contents (can be done with JSP + servlets instead of just servlets that I have now)
  • Remove business logic from servlets and put it into proper EJBs
  • Separate presentation (servlets + JSP) and business logic putting them into WAR and JAR respectively.
  • Implement proper design patterns (for example DTO and DAO, Façade, business delegation and others)
  • Take care of transactions - they are done automatically by database, that should not overlap with other types of transactions.
  • JNDI - everything should be accessed through it
I will continue posting relevant information on the project in this blog. 

Monday, February 14, 2011

Valentine's Day post

It is already 4 a.m. of the Valentine's Day and I have finally finished the project. Of course it has a number of things, that was possible to do better. I had to exclude much of what I originally planned from the project scope because of limited time resources.

What I finally got:

The Java dynamic web application implements 3-layered architecture with

  • Web tier in Java EE Servlets
  • Business-logic tier in EJB 3.0 Stateful and Stateless beans
  • Persistence tier in Hibernate 3.2.5
The main issue is that web tier is too "thick" in this application, because of that the separation between content and presentation was not properly reached everywhere. The issue occurred on the initial phase of the project, in the beginning of work with servlets. As all problems of the early stages, this one was hard to solve later. 

Sunday, February 13, 2011

Final Report and what remains to be done.

In parallel with continued improvements of the project, today I began to compose a final report on it. Schemes, diagrams as well as plain-text words take time, and there is not much of it left.

For now I want to make a conclusion of what is yet to be done:

  1. Final report
  2. Login function: stateful beans + servlet for it (session)
  3. Cart function: stateful bean + servlet (that should be the same session)
  4. Further work on separating the content and presentation.
Because of the recent issue with the Hibernate I decided to remove the "Registration" option from the application. It was supposed to insert data into the database (new user info), but it was impossible to do so - more information in the previous post.

Saturday, February 12, 2011

Hibernate HQL issue

Previously I was only retrieving the information from database using HQL queries, it worked fine. This time I had to insert some information their. And I suddenly found out that it is not that trivial.

HQL doesn't support INSERT... VALUES... at all. (Security reasons, I suppose). The documentation says it supports INSERT INTO...SELECT... and gives some examples about that. But when I try to run such queries they show an exception: "query must begin with SELECT or FROM".
I wonder, how could that be, if in their own documentation (http://docs.jboss.org/hibernate/core/3.3/reference/en/html/batch.html) they state that this:

insert into DelinquentAccount (id, name) select c.id, c.name from Customer c where ...

should work.

I am puzzled about how to do it properly. Their is absolutely not enough time to change the architecture now. If anybody has any suggestions, feel free to express them.

Update on the 13.02.2011: I am sure it is possible to insert info into the database using Hibernate, but I couldn't find any trivial way. Due to the time limitations I will have to exclude that from the project scope.

Update on the 29.06.2011: At last found the solution for this issue! See post from 29.06.2011

Thursday, February 10, 2011

New achievements: interface

Yesterday I finished working on the presentation part of the project. I developed all the servlets to represent the basic structure of the web application. Also I attached some of the previously developed Enterprise Java Beans to process data from the database.
By now I can say that my project will be an online bookstore - classical example.  

Tuesday, February 8, 2011

Exams...

Unfortunately I had to make a forced break in the project work process because of 3 exams. Tomorrow is the last one and I will continue the work after it is over.

By the way: Happy Birthday to me! :-)

Thursday, February 3, 2011

Achievements again

Finally I managed to combine all the required technologies. Now a Servlet represents a piece of business-logic which gets data from database through Hibernate session. The problem was with the last part. In the class, that interacts with Hibernate objects, instead of using the current Hibernate session, it was necessary to create a new one (unlike what was written in a tutorial):

this.session = HibernateBookUtil.getSessionFactory().openSession();

because otherwise the class couldn't "see" the current session. Maybe this issue is really basic but for me it was very confusing. 

Wednesday, February 2, 2011

Problems of technology integration

I am having a lot of issues on the integration of Hibernate with EjB and Servlets, it is just frustrating. When they don't work, they show exceptions, of course. It seems to me that Captain Obvious himself is writing those exceptions for me :)
Seriously: "A system exception occurred during an invocation on EJB BookController method". He told me that an exception happened, that's very informative, thank you, Captain Obvious! Of course they seem truly un-googlable.

Sorry, this post was full of frustration. 

Tuesday, February 1, 2011

Short notice

The Hibernate reverse engineering method is very convenient, but lacks a very important functionality. In case you changed the database it is impossible to add POJO by this method incrementally. So the best solution is to begin with the base and don't change it during the project. That is not always possible.

Important: Maybe I was just unable to find and use the right functionality. So I am open for recommendations on this issue.