java - Spring是否受底层数据库影响?

标签 java spring hibernate postgresql spring-mvc

我正在尝试写一个关于如何开始使用 Spring-boot+Tomcat+React.js 的指南

这是一个针对拥有许多不同开发人员的项目的教育作品。我们知道我们将使用 PostGreSQL,但我希望指南尽可能切中要点。

Spring 代码是否受到底层数据库选择的影响?

来自:https://spring.io/blog/2015/09/01/react-js-and-spring-data-rest-part-1-basic-features

Spring Boot makes it extremely convenient for programmers to quickly develop Spring applications using an in-memory database, such as H2, HSQLDB, and Derby. These databases are lightweight, easy to use, and emulates other RDBMS with the help of JPA and Hibernate. Obviously, they don’t provide persistent storage; but they a fast way to test persistent functions of your Spring Boot application without going through the hassles of installing a database server. They are great to use during development when you need to populate your database once your application starts, test your persistent entity mappings, and remove any data when your application ends. To use the embedded databases, you don’t need any special configuration, not even any connection URL. If you are using Maven, you only specify the dependency of the database to use in the POM file. Spring Boot automatically sets up the in-memory database for your use when it finds the database on your classpath.

In-memory databases are useful in the early development stages in local environments, but they have lot’s of restrictions. As the development progresses, you would most probably require an RDBMS to develop and test your application before deploying it to use a production database server, such as Oracle, MySQL, or PostgreSQL.

例如,类(也来自:https://spring.io/blog/2015/09/01/react-js-and-spring-data-rest-part-1-basic-features)

@Data
@Entity
public class Employee {
    private @Id @GeneratedValue Long id;
    private String firstName;
    private String lastName;
    private String description;

    private Employee() {}

    public Employee(String firstName, String lastName, String description) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.description = description;
    }
}

使用 PostGreSQL 而不是内存数据库时必须进行修改吗?

干杯和亲切的问候, 菲利普

最佳答案

没有。

您在 hibernate 配置中配置数据库。对于普通 Hibernate,它是 hibernate.properties 或 hibernate.cfg.xml。它不会影响持久类。

关于java - Spring是否受底层数据库影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909517/

相关文章:

mysql - 组织.hibernate.MappingException : Unable to find column with logical name OnetoOne Mapping

java - 程序为 println(String s) 提供正确的输出;但不是 print(String s);为什么?

java - Spring MVC 在 GET 上隐藏 url 参数

spring - 使用 Spring 的 REST 多部分混合请求(文件+json)

java - 在 EJB-Hibernate 环境中使用 JDBC

java - 如何编写 Hibernate Criteria 以通过 Projection List 获取嵌套对象?

java - 刷新添加一个额外的参数

java - 区分不同处理的类类型的最佳方法

java - 如何将外部 JAR 包含在 Java 类路径中的目录中并运行 Java 类?

java - 如何在maven中使用Project in Project的依赖?