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 - Strutsdoubt in struts i don't understand the concept on Resource bundle in
struts can u please help me out
Doubt in struts - StrutsDoubt 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 - StrutsI 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 thisdoubt this what is the use of "this" and "super" keyword
DOUBT ?DOUBT ? in c++ member function of a class must be public
DoubtDoubt 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
DoubtUser 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
DoubtHow 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
DoubtSubmit 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
Doubtload 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 JSFdoubt regarding JSF Hi,
pls explain what is difference between
struts &JSF?
pls explain what is difference between SPRING &JSF
Doubt Regarding ChartsDoubt 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 doubtValidation 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
Struts Struts How to retrive data from database by using
Struts STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
StrutsStruts what is SwitchAction in
struts StrutsStruts how to learn
struts STRUTS STRUTS Request context in
struts?
SendRedirect () and forward how to configure in
struts-config.xml
strutsstruts 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
StrutsStruts Tell me good
struts manual
strutsstruts what are the 4 methods of
struts framework
strutsstruts 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 strutsstruts 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 - Strutsjava
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
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
StrutsStruts 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
StrutsSetter 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
strutsstruts 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
strutsstruts 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
StrutsStruts 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 strutsstruts 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