Web Architectures class 2010
Monday, July 11, 2011
The project is finished
Ok, the project is done and presented to the professor. That is good, I learned a lot while working on this application.
Saturday, July 2, 2011
Transactions
Today I found a really good way to deal with transaction management in EJB 3.0 and Hibernate.
I found it on a Java Developer's Forum called "Coderanch", here: http://www.coderanch.com/t/216252/ORM/java/hibernate-Container-Managed-Transactions-CMT
It proposes the usage of container managed transactions (CMT) on the level of EJB beans together with the transactions in Hibernate session.
Like this: When a CMT transaction in an EJB bean is running, and the Hibernate transaction is started, it joins the CMT one.
I was worrying there might be some conflict about it, but looks like everything is fine. It is just necessary to explicitly set the transaction annotation for each bean:
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import static javax.ejb.TransactionAttributeType.*;
@Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER) //CMT type transaction
@TransactionAttribute(value=REQUIRED) //Required as its attribute
public class MyEJB implements MyEJBRemote {
.... }
******************* Update: *******************
By some reason the NetBeans 6.9 doesn't resolve the input for this code correctly, so in case you copy it please make sure you copy the imports too.
I found it on a Java Developer's Forum called "Coderanch", here: http://www.coderanch.com/t/216252/ORM/java/hibernate-Container-Managed-Transactions-CMT
It proposes the usage of container managed transactions (CMT) on the level of EJB beans together with the transactions in Hibernate session.
Like this: When a CMT transaction in an EJB bean is running, and the Hibernate transaction is started, it joins the CMT one.
I was worrying there might be some conflict about it, but looks like everything is fine. It is just necessary to explicitly set the transaction annotation for each bean:
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import static javax.ejb.TransactionAttributeType.*;
@Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER) //CMT type transaction
@TransactionAttribute(value=REQUIRED) //Required as its attribute
public class MyEJB implements MyEJBRemote {
.... }
******************* Update: *******************
By some reason the NetBeans 6.9 doesn't resolve the input for this code correctly, so in case you copy it please make sure you copy the imports too.
Achievements: user session
The project is almost done. Tonight I managed to transfer the user session handling from previously used Http session into session, stored into the EJB 3.0 Stateful Bean.
In general, some testing was done and the UI slightly changed for better usability.
In general, some testing was done and the UI slightly changed for better usability.
Thursday, June 30, 2011
To Do List
Currently most of the presentation layer is transferred to JSP with Servlets instead of just plain servlets as it was done previously, in the first version of the project. That gives a clear separation of business logic and interface elements.
Also a registration possibility was added, in the previous version the users could use only the those user names, that were already in the DB. (That was due to Hibernate DB writing problem)
As the project is coming to it's final stage, here is a list of things that still need to be done:
The priority things to be implemented are the following:
- Proper handling of transactions - only Hibernate transactions are to be used and I should switch off the other types in order to prevent conflicts
- User session needs to be transferred from plain http session to a session, supported by a stateful bean
- Documentation of this new version
- General improvements and testing
Also a registration possibility was added, in the previous version the users could use only the those user names, that were already in the DB. (That was due to Hibernate DB writing problem)
As the project is coming to it's final stage, here is a list of things that still need to be done:
The priority things to be implemented are the following:
- Proper handling of transactions - only Hibernate transactions are to be used and I should switch off the other types in order to prevent conflicts
- User session needs to be transferred from plain http session to a session, supported by a stateful bean
- Documentation of this new version
- General improvements and testing
Wednesday, June 29, 2011
Writing to a DB with Hibernate
Finally I managed to solve that really old problem of writing into database with the Hibernate approach. (see post from 12.02.2011)
Previously I was thinking, that just as reading from a DB it should be working with HQL queries. They didn't work.
Now I know how to do it correctly: there is a safer method in the Hibernate session - saveOrUpdate. It simply writes an instance of a Hibernate-generated database entity class in to the base. And of course it is possible to use transaction for that.
Previously I was thinking, that just as reading from a DB it should be working with HQL queries. They didn't work.
Now I know how to do it correctly: there is a safer method in the Hibernate session - saveOrUpdate. It simply writes an instance of a Hibernate-generated database entity class in to the base. And of course it is possible to use transaction for that.
Monday, June 27, 2011
JNDI and Service Locator pattern
Right now I am in the process of developing a portable and server independent way of data exchange between the layers of architecture and the architectural elements. So far I found the following methods being proposed in literature:
- accessing through plain JNDI
- using Service Locator design pattern (not recommended by for example: http://www.javalobby.org/articles/service-locator/)
Looks like the question of the design patterns and their usage is changing as the newer versions of EJB appear. I will have to spend more time on this issue than was planned earlier.
Updated:
A little addition about design patterns by Paul Wheaton (2006):
"I think that any pattern being used in an application could/should(/must!) be trumped by the simplest thing that could possibly work."
Looks like I should keep that in mind.
- accessing through plain JNDI
- using Service Locator design pattern (not recommended by for example: http://www.javalobby.org/articles/service-locator/)
Looks like the question of the design patterns and their usage is changing as the newer versions of EJB appear. I will have to spend more time on this issue than was planned earlier.
Updated:
A little addition about design patterns by Paul Wheaton (2006):
"I think that any pattern being used in an application could/should(/must!) be trumped by the simplest thing that could possibly work."
Looks like I should keep that in mind.
Saturday, June 25, 2011
Achievements
Today I managed to organize the 3 tiers - presentation, business-logic and persistence in jar and war accordingly. Previously I had some issues with Hibernate concerning that and had to store everything, related to Hibernate in war, now this one is solved.
The next issue of the first version I have to take care of is the proper division of the presentation layer between JSP and Servlets.
So far I have studied a several tutorials, but they didn't cover those questions, so I look further.
The next issue of the first version I have to take care of is the proper division of the presentation layer between JSP and Servlets.
So far I have studied a several tutorials, but they didn't cover those questions, so I look further.
Sunday, June 19, 2011
EJB 3.1
Currently I am working on the possibility to switch to EJB 3.1 instead of EJB 3.0. It follows the tendency for further simplification, declared by version 3.0. For example it provides the "interfaceless" mode. Now I am studying the issues that might appear for cooperation with Hibernate and other technologies.
What is clear so far: EJB 3.1 naturally cooperates with NetBeans 6.9-7.0 and GlassFish 3.x, which is already good.
Any further discoveries on this question will follow.
What is clear so far: EJB 3.1 naturally cooperates with NetBeans 6.9-7.0 and GlassFish 3.x, which is already good.
Any further discoveries on this question will follow.
Saturday, June 11, 2011
Time to continue
Now I can see the gap in my schedule and will use it to start working on the project again. A lot needs to be done and there is time only till the 3rd of July.
The To-do list for the project is in the previous post (from February, that is)
The To-do list for the project is in the previous post (from February, that is)
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.
Subscribe to:
Comments (Atom)