我有一个在Spring引导上构建的应用程序,它使用HSQL数据库上的JPA存储库。
问题是,在应用程序运行时,我创建了一个实体,并将其正确持久保存到数据库中(可以在数据库管理器中看到)。但是从eclipse关闭应用程序后,所有数据都将被删除。
这样保存
@Service
public class NotificationService {
@Autowired
private NotificationRepository notificationRepository;
public void notifyRefreshArticles(){
Notification notification = new Notification();
notification.setCreatedAt(LocalDateTime.now());
notification.setNotificationSeverity(NotificationSeverity.NORMAL);
notification.setNotificationType(NotificationType.REFRESH_ARTICLES);
notificationRepository.save(notification);
}
}
我很确定它的配置问题,但是使用Spring Boot基本上只有我拥有的配置是此配置文件。
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
spring.datasource.url=jdbc:hsqldb:hsql://localhost/rr_app_database
spring.datasource.username=XXXXXX
spring.datasource.password=XXXXXX
spring.datasource.show-sql=true
您的配置属性中是否有hbm2ddl文本。应该将其设置为,update
或者none
,显然您可能已经设置了create-drop
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句