struts - hibernate doubt

struts - hibernate doubt

Hello.

I'm developing a web application using Struts 1.0 and Hibernate (I'm a beginner). I've been reading your web and I've seen that in the Struts Action methods you use an Hibernate Plugin in this way:

public ActionForward myMethod (.......){ ServletContext context = request.getSession().getServletContext(); SessionFactory _factory = (SessionFactory);
context.getAttribute(HibernatePlugIn.SESSIONFACTORYKEY); Session session = _factory.openSession(); Transaction tx = session.beginTransaction(); //... do session stuff tx.commit(); session.flush(); session.close(); ...

What is the difference between doing this and this other?

public ActionForward myMethod (.......){

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
       Transaction tx = session.beginTransaction();
        //... do session stuff 
        tx.commit();
      .....

Some questions: 1.- What is the best option? 2.- I've read that it's not necessary to close Hibernate session nor flush the session if you use .getCurrentSession(). Is it true?

Thanks in advance.

View Answers









Related Tutorials/Questions & Answers:
doubt in struts - Struts
doubt in struts   i don't understand the concept on Resource bundle in struts can u please help me out
Doubt in struts - Struts
Doubt in struts  I am new to Struts, Can anybody say how to retrieve data from database and display it in jsp. Some said to use beans but i dont know how to do. Please help me in this regard. It will be helpful, if explained
Advertisements
I have a doubt regarding action - Struts
I have a doubt regarding action   hi, I have doubt regarding struts,I got response through jsp and once again it redirecting to action..., Please check Action Mapping in the struts-config.xml. If you have any problem
doubt this
doubt this  what is the use of "this" and "super" keyword
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
doubt regarding JSF
doubt regarding JSF  Hi, pls explain what is difference between struts &JSF? pls explain what is difference between SPRING &JSF
Doubt Regarding Charts
Doubt Regarding Charts  Hi, Can you please help me out by answering "hoe to include charts in core java code and struts code" thanks in advance, Swaroop Eswara   Please visit the following link: Jfreechart
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give
doubt
doubt
doubt
Doubt
DOUBT
doubt
doubt
Struts
Struts   How to retrive data from database by using Struts
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
Struts
Struts  what is SwitchAction in struts
Struts
Struts  how to learn struts
STRUTS
STRUTS   Request context in struts? SendRedirect () and forward how to configure in struts-config.xml
struts
struts  in industry, struts 1 and struts 2. which is the best? which is useful as a professuional   Have a look at the following link: Struts Tutorials
Struts
Struts  Tell me good struts manual
struts
struts  what are the 4 methods of struts framework
struts
struts shopping cart project in struts with oracle database connection  shopping cart project in struts with oracle database connection   Have a look at the following link: Struts Shopping Cart using MySQL
Struts
Struts   When Submit a Form and while submit is working ,press the Refresh , what will happen in Struts
struts
struts  Hi what is struts flow of 1.2 version struts? i have struts applicatin then from jsp page how struts application flows Thanks Kalins Naik   Please visit the following link: Struts Tutorial
java struts DAO - Struts
java struts DAO  hai friends i have some doubt regarding the how to connect strutsDAO and action dispatch class please provide some example to explain this connectivity. THANKS IN ADVANCE
struts
struts   how to write Dao to select data from the database
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
Struts
Struts  Hi i am new to struts. I don't know how to create struts please in eclipse help me
struts
struts   Hi how struts flows from jsp page to databae and also using validation ? Thanks Kalins Naik
Struts
Setter methods of form bean class in Struts applications  who calls the setter methods of form bean class in struts applications
Struts
Struts   in struts I want two struts.xml files. Where u can specify that xml files location and which tag u specified
Struts
Struts   What is called properties file in struts? How you call the properties message to the View (Front End) JSP Pages
struts
struts  which is the best book to study struts on own? please tell me   You can learn struts through the following books: 1)Programming Jakarta Struts By Chuck Cavaness 2)Professional Jakarta Struts By James Goodwill
struts
struts  which is the best book to study struts on own? please tell me   You can learn struts through the following books: 1)Programming Jakarta Struts By Chuck Cavaness 2)Professional Jakarta Struts By James Goodwill
Struts
Struts  How Struts is useful in application development? Where to learn Struts? Thanks   Hi, Struts is very useful in writing web... performance Java web applications that runs on Java enabled application servers. Struts
Struts - Struts
Struts for beginners  struts for beginners example
struts
struts  how to start struts?   Hello Friend, Please visit the following links:ADS_TO_REPLACE_1 http://www.roseindia.net/struts/ http... through which you can easily learn the struts. ThanksADS_TO_REPLACE_2

Ads