logical_way (2) [Avatar] Offline
#1
I am testing Hibernate one sunday and my whole sunday got wasted. i was making a simple application with POJO style architecture. I am using WebSphere 5.0 Application Developer and using it's own inbuild JNDI Context and used Struts 1.1 framework. And also used HibernateUtil.java class as given in book. The only trick is made an interface GenericDAO.java responsible for only two methods presently [load and save of my model.]. Then I made two tables in MySql 4.0 using mysql-connector-3.0.8-stable-bin.jar jdbc driver one hold user information and other address, there is one to one mapping between both with loginid primary key in user and foreign key in address table. And used following mapping

[b]
For User:
---------
<one-to-one name="address" class="Address" cascade="save-update"/>

For Address:
---------
<one-to-one name="user" class="User" constrained="true"/>
[b]

and provided getter/setter for both classes in both classes.

Then I made UserDAO extending from GenericDAO[with load and save methods] having other user related bussiness logic.

Then I have Factory pattern called BaseDAOFactory that returns implementation of GenericDAO interface.

Code snippet is as follows:
---------------------------
[b]
public class BaseDAOFactory{

......

public static GenericDAO getDAOInstance(String type){
if(type.equals("user"))
return new UserDAOImpl();
......
.....
}
[b]

Since user is implementing USERDAO that extends GenericDAO so it should work.

Now in action class I called this implementation in addUser method made in my action called UserManagementAction extending Struts DispatchAction Class
as follows:

[b]
public ActionForward addUser(...arguments....){
UserForm user = (UserForm) form;
User u = user.getUser();//returns set data from request
//encapsulated in User model associated in mapping resource.
try{
UserDAOImpl impl = (UserDAOImpl) BaseDAOFactory.getDAOInstance("user");
impl.save(u);
}catch(DataException){

}
}
[b]

Now, the much waited UserDAOImpl class it is using HibernateUtil.java as given in the book to load and save objects obtaining session using threadlocal pattern etc.

[b]
public class UserDAOImpl implements UserDAO{

public UserDAOImpl(){
HibernateUtil.beginTransaction();
}

public void save(User user) throws DataException{
Session s = HibernateUtil.openSession();
s.save(user);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}
........
.......

}
[b]

Alas,but this is not working when ever i try to save it gives no error but my server stops also there is Window's VC++ debugger pops up asking for debugging or exiting the application resulting ins howing me all the machine language code of JVM. I am using Windows 2K pro.

Can u tell me what's the problem as soon as possible pls.
My email id is shailesh.kushwaha@tatainfotech.com. We are planning to use Hibernate in our project and I am testing it checking its feasability and scalability also efficiency. i am quite impressed by its simplicity especially the way ti is handling all the mappings its superb. Keep it up. Thanks in advance.