【发布时间】:2016-08-04 22:40:38
【问题描述】:
我有一个基于 Spring Boot 构建的应用程序,使用 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
【问题讨论】:
-
显示您的数据源。看起来您正在使用通常在内存中使用的 hsqldb。如果是这样,当你关闭应用程序时它当然会死。
-
stackoverflow.com/questions/6364171/… 查看此链接。这可能是一个类似的问题。
标签: java spring jpa spring-boot spring-data