首页 > 解决方案 > SpringBoot 和 Oracle 的问题:创建列“created Date”时间戳时出错:Unexpected token

问题描述

我有一个 springboot 应用程序,使用 yaml 配置进行配置。当它为 PgSql 配置时,它可以工作,但是当我尝试为 oracle 配置它并运行应用程序时,我收到以下错误:

liquibase.exception.DatabaseException: Token SQL92 non supportato nella posizione: 417 [Failed SQL: 
CREATE TABLE MVOLPINI.desk_user (
id NUMBER(38, 0) GENERATED BY DEFAULT AS IDENTITY NOT NULL, 
login VARCHAR2(50) NOT NULL, 
password_hash VARCHAR2(60), 
first_name VARCHAR2(50), 
last_name VARCHAR2(50), 
email VARCHAR2(100), 
image_url VARCHAR2(256), 
activated NUMBER(1) NOT NULL, 
activation_key VARCHAR2(20), 
reset_key VARCHAR2(20), 
reset_date TIMESTAMP, created_by VARCHAR2(50) NOT NULL, 
created_date TIMESTAMP DEFAULT ${now} NOT NULL, 
last_modified_by VARCHAR2(50), last_modified_date TIMESTAMP, 
tenant_id NUMBER(38, 0), 
CONSTRAINT PK_DESK_USER PRIMARY KEY (id), 
UNIQUE (login), 
UNIQUE (email))
]

在创建列创建日期时,hibernate 似乎试图传递错误的默认值 ({now})。这是实体:

@MappedSuperclass
@Audited
@EntityListeners(AuditingEntityListener.class)
public abstract class AbstractAuditingEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @CreatedBy
    @Column(name = "created_by", nullable = false, length = 50, updatable =false)
    @JsonIgnore
    private String createdBy;

    @CreatedDate
    @Column(name = "created_date", nullable = false, updatable=false)
    @JsonIgnore
    private Instant createdDate = Instant.now();

    @LastModifiedBy
    @Column(name = "last_modified_by", length = 50)
    @JsonIgnore
    private String lastModifiedBy;

    @LastModifiedDate
    @Column(name = "last_modified_date")
    @JsonIgnore
    private Instant lastModifiedDate = Instant.now();

我在代码中的任何地方都找不到导致问题的令牌 {now}。认为它是由注释 @CreatedDate 生成的,我试图用其他注释代替它,例如 @Temporal 并用 Date 更改 Instant 类型,但我得到了同样的错误。有人可以帮我吗?

这是yaml配置:

 logging:
    level:
        ROOT: INFO
        it.dedagroup.todo: INFO
        io.github.jhipster: INFO

spring:
    devtools:
        restart:
            enabled: false
        livereload:
            enabled: false 
    datasource:
        type: com.zaxxer.hikari.HikariDataSource
        url: jdbc:oracle:thin:@172.17.34.20:1521:db12Test
        username: mvolpini
        password: password1
        driver-class-name: oracle.jdbc.driver.OracleDriver
    jpa:
        database-platform: org.hibernate.dialect.Oracle12cDialect
        database: ORACLE
        show-sql: false
        properties:
            hibernate.id.new_generator_mappings: true
            hibernate.cache.use_second_level_cache: false
            hibernate.cache.use_query_cache: false
            hibernate.generate_statistics: false
    mail:
        host: localhost
        port: 25
        username:
        password:
    thymeleaf:
        cache: true

liquibase:
    contexts: prodOracle

# ===================================================================
# To enable SSL, generate a certificate using:
# keytool -genkey -alias DeskBackend -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650
#
# You can also use Let's Encrypt:
# https://maximilian-boehm.com/hp2121/Create-a-Java-Keystore-JKS-from-Let-s-Encrypt-Certificates.htm
#
# Then, modify the server.ssl properties so your "server" configuration looks like:
#
# server:
#    port: 8443
#    ssl:
#        key-store: keystore.p12
#        key-store-password: <your-password>
#        keyStoreType: PKCS12
#        keyAlias: DeskBackend
# ===================================================================
server:
    port: 8180
    compression:
        enabled: true
        mime-types: text/html,text/xml,text/plain,text/css, application/javascript, application/json
        min-response-size: 1024

# ===================================================================
# JHipster specific properties
#
# Full reference is available at: http://www.jhipster.tech/common-application-properties/
# ===================================================================

jhipster:
    http:
        version: V_1_1 # To use HTTP/2 you will need SSL support (see above the "server.ssl" configuration)
    cache: # Cache configuration
        ehcache: # Ehcache configuration
            time-to-live-seconds: 3600 # By default objects stay 1 hour in the cache
            max-entries: 1000 # Number of objects in each cache entry
    # CORS is only enabled by default with the "dev" profile, so BrowserSync can access the API
    cors:
        allowed-origins: "*"
        allowed-methods: "*"
        allowed-headers: "*"
        exposed-headers: "Authorization"
        allow-credentials: true
        max-age: 1800
    security:
        authentication:
            jwt:
                secret: d593dbdfe07821e0f92f45cdef8bdccba69757ff
                # Token is valid 24 hours
                #token-validity-in-seconds: 86400
                #token-validity-in-seconds-for-remember-me: 2592000
                # Token is valid 1 year
                token-validity-in-seconds: 946080000
                token-validity-in-seconds-for-remember-me: 946080000
    mail: # specific JHipster mail property, for standard properties see MailProperties
        from: oracle@localhost
        base-url: http://127.0.0.1:8080
    metrics: # DropWizard Metrics configuration, used by MetricsConfiguration
        jmx.enabled: true
        graphite: # Use the "graphite" Maven profile to have the Graphite dependencies
            enabled: false
            host: localhost
            port: 2003
            prefix: DeskBackend
        prometheus: # Use the "prometheus" Maven profile to have the Prometheus dependencies
            enabled: false
            endpoint: /prometheusMetrics
        logs: # Reports Dropwizard metrics in the logs
            enabled: false
            report-frequency: 60 # in seconds
    logging:
        logstash: # Forward logs to logstash over a socket, used by LoggingConfiguration
            enabled: false
            host: localhost
            port: 5000
            queue-size: 512


# ===================================================================
# Application specific properties
# Add your own application properties here, see the ApplicationProperties class
# to have type-safe configuration, like in the JHipsterProperties above
#
# More documentation is available at:
# http://www.jhipster.tech/common-application-properties/
# ===================================================================

application:

这是关于 liquibase 的配置:

    @Bean
    public SpringLiquibase liquibase(@Qualifier("taskExecutor") TaskExecutor taskExecutor,
            DataSource dataSource, LiquibaseProperties liquibaseProperties) {

        // Use liquibase.integration.spring.SpringLiquibase if you don't want Liquibase to start asynchronously
        SpringLiquibase liquibase = new AsyncSpringLiquibase(taskExecutor, env);
        liquibase.setDataSource(dataSource);
        liquibase.setChangeLog("classpath:config/liquibase/master.xml");
        liquibase.setContexts(liquibaseProperties.getContexts());
        liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema());
        liquibase.setDropFirst(liquibaseProperties.isDropFirst());
        if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_NO_LIQUIBASE)) {
            liquibase.setShouldRun(false);
        } else {
            liquibase.setShouldRun(liquibaseProperties.isEnabled());
            log.debug("Configuring Liquibase");
        }
        return liquibase;
    }

标签: oraclehibernatetimestamptoken

解决方案


推荐阅读