java


Hibernate 5.2.10 with Spring 4.3.8 Error in org.hibernate.SessionFactory.openSession()


I'm using Hibernate 5.2.10 and Spring 4.3.8 and when I'm trying to run my main file I'm getting error.
Main file
public static void main(String[] args) {
// TODO Auto-generated method stub
Resource r = new ClassPathResource("applicationContext.xml");
BeanFactory bean = new XmlBeanFactory(r);
DayBookDao dayBookDao = (DayBookDao) bean.getBean("dayBook");
DayBookData dayBook = new DayBookData();
dayBook.setAccountType("Bank Account");
dayBook.setTransType("Receipt");
dayBook.setOppAccount("Profit-Loss");
dayBook.setAmount(15000);
dayBook.setTransDate(new Date());
dayBookDao.saveDayBookData(dayBook);
}
My Entity Class
#Entity
#Table
public class DayBookData {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
#OneToOne
#JoinColumn(name= "vendor_id")
private Vendor vendor;
#Column(name="account_type")
private String accountType;
#Column(name="trans_type")
private String transType;
#Column(name="trans_date")
private Date transDate;
#Column(name="opp_account")
private String oppAccount;
#Column(name="voucher_number")
private String voucherNumber;
#Column
private long amount;
#Column
private String narration;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Vendor getVendor() {
return vendor;
}
public void setVendor(Vendor vendor) {
this.vendor = vendor;
}
public String getAccountType() {
return accountType;
}
public void setAccountType(String accountType) {
this.accountType = accountType;
}
public String getTransType() {
return transType;
}
public void setTransType(String transType) {
this.transType = transType;
}
public Date getTransDate() {
return transDate;
}
public void setTransDate(Date transDate) {
this.transDate = transDate;
}
public String getOppAccount() {
return oppAccount;
}
public void setOppAccount(String oppAccount) {
this.oppAccount = oppAccount;
}
public String getVoucherNumber() {
return voucherNumber;
}
public void setVoucherNumber(String voucherNumber) {
this.voucherNumber = voucherNumber;
}
public long getAmount() {
return amount;
}
public void setAmount(long amount) {
this.amount = amount;
}
public String getNarration() {
return narration;
}
public void setNarration(String narration) {
this.narration = narration;
}
}
applicationContext.xml
<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/db1?autoReconnect=true&useSSL=false"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="mysessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="packagesToScan" value="entityClasses"></property>
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="template" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="mysessionFactory"></property>
</bean>
<bean id="vendor" class="vendors.VendorDao">
<property name="hibernateTemplate" ref="template"></property>
</bean>
<bean id="dayBook" class="accountBooks.DayBookDao">
<property name="hibernateTemplate" ref="template"></property>
</bean>
</beans>
When I'm trying to run my main file I'm getting this error:
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:330)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:241)
at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:462)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:398)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:379)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:718)
at accountBooks.DayBookDao.saveDayBookData(DayBookDao.java:19)
at accountBooks.TestDayBook.main(TestDayBook.java:27)

Related Links

Java: Convert command array to string that can execute in bash
Value added to array is NULL?
Maven archetype:generate | Build Failure
store output of two Java programs in bash variable
Google Analytic java include-empty-rows
Inserting JSON object without JSON schema in Mongo DB through Mongoose (Node JS)
I want to select data between two dates
Why is method A flawed compared to B for UVa online judge 100 (3n+1)?
Unresolved compilation problems: The type java.lang.String cannot be resolved. Implicit constructor Object() is undefined
JPanel gets paintComponent gets called when child is entered
Canonical form of field
Eclipe - handling accents in java file
Error in Hibernate formula: ORA-00904 - Wrong identifier
Find element in ArrayList Java
How to translate the codes about blur detection with Opencv from C++ to java
How to create a command line to get a savefile? [closed]

Categories

HOME
compiler-construction
date
deployment
mfc
smarty
fft
platform-builder
objectgears
tizen-web-app
jxls
ckeditor
yum
in-app-purchase
directx
node-notifier
vifm
leiningen
iron-router
workload-scheduler
ghc
progressive-web-apps
transformation
facebook-page
evopdf
connection-string
pythonanywhere
conemu
paging
elasticsearch-ruby
ejabberd-module
google-rich-snippets
bosh
phpfreechat
repo
host
lto
azure-ml
user-controls
gulp-sourcemaps
dynamic-reports
wso2carbon
appcompat
chain-builder
dropbox-php
setter
pearson
sonarlint-vs
abcpdf9
removechild
httplistener
jwplayer7
ready-api
fadeout
apachebench
teamcity-8.0
ideamart
device-orientation
lustre
java.util.concurrent
java-metro-framework
device-manager
internet-connection
code-access-security
rdl
bitcoinj
ceil
aapt
hippomocks
poller
rtmfp
algebraic-data-types
openlaszlo
page-layout
apc
ftps
eventual-consistency
yui-compressor
plasma
selected
frameset
word-processor
parametric-equations
dotnethighcharts
semantic-diff
code-cleanup
window-management
django-tagging
table-footer
sql-server-profiler
rescale
meego
sustainable-pace
private-members
msdev
ugc
misv

Resources

Encrypt Message