Когда я запускаю проект, база данных будет построена, но данные не будут сохранены.Я пользуюсь базой данных Postgre. id add Библиотеки Spring, Hibernate и Postgre.
Спасибо за помощь в решении моей проблемы.
Мой код
public class PersonManager extends HibernateDaoSupport {
public void RegisterPerson()
{
Person person = new Person();
person.setId(0);
person.setName("ali");
person.setFamily("eslami");
getHibernateTemplate().saveOrUpdate(person);
}
public static void main (String[] arg0)
{
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("beans.xml"));
PersonManager aa = (PersonManager) beanFactory.getBean("p");
aa.RegisterPerson();
}
}
bean.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="driverManagerDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://127.0.0.1:5432/db44" />
<property name="username" value="login" />
<property name="password" value="123456" />
</bean>
<bean id="localSessionFactoryBean" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="driverManagerDataSource"/>
<property name="mappingResources">
<list>
<value>model/to/person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
</props>
</property>
</bean>
<bean id="p" class="model.bl.PersonManager">
<property name="sessionFactory" ref="localSessionFactoryBean" />
</bean>
</beans>
** Мои ошибки в терминале **
May 30, 2018 12:46:14 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
May 30, 2018 12:46:14 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: org.postgresql.Driver
May 30, 2018 12:46:14 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.3.0.CR2}
May 30, 2018 12:46:14 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
May 30, 2018 12:46:15 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.3.Final}
May 30, 2018 12:46:16 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
May 30, 2018 12:46:16 AM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl makeLobCreatorBuilder
INFO: HHH000422: Disabling contextual LOB creation as connection was null
May 30, 2018 12:46:16 AM org.hibernate.type.BasicTypeRegistry register
INFO: HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@ead359
May 30, 2018 12:46:16 AM org.hibernate.type.spi.TypeConfiguration$Scope setSessionFactory
WARN: HHH000233: Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@84f433 after already scoped org.hibernate.internal.SessionFactoryImpl@84f433
May 30, 2018 12:46:17 AM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@13c0293'
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
at org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1127)
at org.springframework.orm.hibernate4.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:685)
at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:341)
at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:309)
at org.springframework.orm.hibernate4.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:682)
at model.bl.PersonManager.RegisterPerson(PersonManager.java:24)
at model.bl.PersonManager.main(PersonManager.java:33)
Я пользователь базы данных Postgre.id add Библиотеки Spring, Hibernate и Postgre.
Спасибо за помощь в решении моей проблемы.