سؤال

why after execute such code without flush(),database will change?

public static void main(String args[]){

ApplicationContext ac = new FileSystemXmlApplicationContext("src/main/resources/config/spring/spring-common.xml");

SessionFactory sessionFactory = (SessionFactory)ac.getBean("sessionFactory");

Session session = sessionFactory.openSession();

Student student = new Student();

student.setName("zyc");

session.save(student);
}

I use this class to create sessionFactory.

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
هل كانت مفيدة؟

المحلول

The "database will change" here if Student is defined to use IDENTITY for id generation. Meaning that the insert for Student will happen immediately on the call to save for IDENTITY based generators.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top