Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JPA data removed after shutdown of application

i have an application thats build on Spring boot, using JPA repositories on HSQL database.

Problem is that while application is running, I create an entity,and it's persisted correctly to database(can be seen in database manager). But after application shutdown from eclipse, all data is removed;

Saving is performed like this

@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);
    }
}

I pretty sure its configuration issue,but with spring boot basically only configuration that i have is this configuration file.

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
like image 539
Ján Srniček Avatar asked Apr 13 '16 17:04

Ján Srniček


2 Answers

Do you have hbm2ddl text somewhere in your configuration properties. It should be set to update or none, apparently you might have create-drop.

like image 174
LearningPhase Avatar answered Nov 09 '22 05:11

LearningPhase


Specify a local filename in application.properties data source URL:

spring.datasource.url=jdbc:hsqldb:file:/home/username/testedb

You can remove the spring.datasource.driver-class-name property as Spring Boot detects it by URL property.

like image 43
ntroccoli Avatar answered Nov 09 '22 05:11

ntroccoli