2013年9月23日星期一

spring3.1 + hibernate4.0 problems of people seeking answers, hope can help solve

CSDN


is the case with , but my other use are hibernate4




start without error, run time will be incorrect

java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder
org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession (SessionFactoryUtils.java: 287)
org.springframework.orm.hibernate3.SessionFactoryUtils.getSession (SessionFactoryUtils.java: 233)
org.springframework.orm.hibernate3.HibernateTemplate.getSession (HibernateTemplate.java: 457)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute (HibernateTemplate.java: 393)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession (HibernateTemplate.java: 374)
org.springframework.orm.hibernate3.HibernateTemplate.save (HibernateTemplate.java: 683)
can not say four into three , but the problem is that there is no HibernateTemplate org.springframework.orm.hibernate4 this utility class , but I would like to use HibernateTemplate class how with this tool , or have a new tool spring3.1 classes are available ? But looking spring3.1 document did not explain this, ah , seeking answers, thank you
------ Solution ------------------------ --------------------
landlord sessionFactory is used
org.springframework.orm.hibernate3.LocalSessionFactoryBean it,
recommendations and org.springframework.orm.hibernate4.HibernateTransactionManager want to replace the corresponding class
------ For reference only ----------------- ----------------------
  The reply on 2011-12-26 09:01:23 deleted by moderator

------ For reference only ---------------------------------- -----
  The reply on 2011-12-26 11:34:56 deleted by moderator

------ For reference only ---------------------------------- -----
java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder

This is not a good solution?

org.springframework.orm.hibernate4.SessionHolder this class , you can not turn into : org.springframework.orm.hibernate3.SessionHolder

Why column ? Please optimistic version landlord , a hibernate3 one is four


your transaction is used in 4.0 of
but your session is using 3.0


that the white version of the problem , you put the uniform version is no problem .
------ For reference only -------------------------------------- -


I use hibernate4 the sessionFactory ah, trouble and then help facie , thank
------ For reference only ------------------ ---------------------

I also know that version of the problem

I use hibernate4 the sessionFactory ah, trouble and then help look , thank you , my only place is with hibernate3


problem is that I now can not find the jar spring3.1 bag hibernate4.HibernateTemplate this helper class , I want to use this helper class , we would like to ask spring3.1 has this class alternate with class do or how
------ For reference only ------------------------------ ---------
seemingly find the reason , https://jira.springsource.org/browse/SPR-8096
English is not good , probably means spring3.1 HibernateTemplate does not provide this kind of help ,
that original hibernateDAO better ? I also get the next according to the native Session sess = sessionFactory.openSession ();
Transaction tx = sess.beginTransaction (); method on the line.
I do not know why the abolition of this helper class , I feel very convenient to use this HibernateTemplate class ah , seeking explanations
------ For reference only --------------- ------------------------
lz, I'm also learning spring3 + hibernate4. jar package can be made ​​about the image and configuration files?
------ For reference only -------------------------------------- -
Big Brother in hibernate4 already abandoned the HibernateTemplate, because hibernate4 where the transaction has been fully achieved such affairs .
I have been able to achieve a functional Spring3.1 + hibernate4.0 project , if necessary friends can add my QQ: 120987555 I can give everyone seminars ....
--- --- For reference only ---------------------------------------
hibernate4 had already abandoned the HibernateTemplate, I use so that you can :
Code:
public class UserDAOIMP implements UserDAO {
private SessionFactory sessionFactory;

public void setSessionFactory (SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

public boolean insertUser (Users user) {
try {
System.out.println ("insert ...");
this.sessionFactory.getCurrentSession (). persist (user);
return true;
} catch (Exception e) {
e.printStackTrace ();
}
return false;
}

}

configuration file:



final success :
into the Action of ....
insert ...
Hibernate: insert into Users (username, password, id) values ​​(?,?,?)


------ For reference only ---------------------------------- -----


Can you send me a copy , e-mail 766322282@qq.com
------ For reference only -------------------- -------------------

I am also very surprised , why not provide hibernateTemplate tools , the trouble also gave me a ah , I am grateful endless 787595261@qq.com
------ For reference only ------------------------------- --------


I also have this question !
------ For reference only -------------------------------------- -
I just came across this problem , the Internet saw a lot of articles , said hibernate4.0 above version of the session that they have encapsulated handling things , and the spring hibernateTemplate things on and hibernate4 things conflict , then spring3.1 above versions simply put hibernateTemplate removed , and now smart with getcurrensession
------ For reference only ---------------------------------------
I in the 10 days of efforts finally spring3.2 hibernate4.1.6 struts2.3.4 collection is completed, and the use of JUnit4.11 tested successfully using tomcat test is successful, the test is successful using weblogic
hibernate and spring full use of annotations
JUnit4.11 test class is very simple, very convenient, two notes on ok
example, the following code can be tested in practical work on this test method will be very fast , you can also inject sessionfactory all OK .
public class TestJunit {
@ Autowired
TeacherManager teacherManager;
@ Test
public void saveTeacher () {
Teacher teacher = new Teacher ();
teacher.setName ("junitName");
teacher.setTitle ("junitTitle");
teacherManager.save (teacher);
}
}

can be said is now the latest technology
If people want to use , please contact QQ: 337418621 Tel: 18610995595
------ For reference only ------------- --------------------------


can send a code to integrate it into my mailbox ?
418175138@qq.com
Extremely grateful !
------ For reference only -------------------------------------- -


code can send a comment to my mail do ?
343899743@qq.com
Extremely grateful !
------ For reference only -------------------------------------- -

do not know the current Spring also support such usage?

------ For reference only ---------------------------------- -----
top, valiant finally understand . This problem card me a week .
------ For reference only -------------------------------------- -

------ For reference only ---------------------------------- -----
send a code to integrate into my mailbox , 1248860846@qq.com Thank you ! !

没有评论:

发表评论