Spring Data JDBC: DataRetrievalFailureException : Unable to cast [oracle.sql.ROWID] to [java.lang.Number]

前端 未结 3 1517
悲哀的现实
悲哀的现实 2021-01-22 14:10

I am new to Spring Data JDBC, and I am struggling to create a simple Dto and get it persisted on the DB.

I am using Spring-Boot 2.1.1.RELEASE and and Oracle 12 Database.

相关标签:
3条回答
  • 2021-01-22 14:35

    I suffered the same problem, while the PR is being included in the next Spring Data JDBC release we can use the following workaround with Spring AOP, It's not "perfect" but enough for us until the underlying problem is solved:

    @Around("execution(public * my-app-pacakage.repository.*.save(..))")
    public Object aspectController(ProceedingJoinPoint jp) throws Throwable {
        try {
            return jp.proceed();
        } catch (DbActionExecutionException e) {
            if (e.getCause() instanceof DataRetrievalFailureException) {
                return jp.getArgs()[0];
            }
            return e;
        } catch(Throwable e) {
            throw e;        
        }       
    }
    
    0 讨论(0)
  • 2021-01-22 14:54

    I think you need to declare the USR_ID field and corresponding sequence in your entity

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XXXX")
    @SequenceGenerator(sequenceName = "YYYY", allocationSize = 1, name = "XXXX")
    Long USR_ID;
    
    0 讨论(0)
  • 2021-01-22 14:55

    Unfortunately, Oracle is not yet fully supported. There is an issue open for creating integration tests for Oracle and the accompanying PR is already fixing some issues, but certainly not all.

    The main problem here is that Oracle does some interesting stuff regarding generated key generation. I see the following options

    a) Don't use key generation on the database side. DATAJDBC-282 makes this more comfortable. But it is so far only in the SNAPSHOT release.

    b) Don't use Oracle. We currently test with MySql, Postgres, H2, HSQLDB and MariaDb

    c) Take a look at the PR mentioned above to see if you can patch it enough to work.

    I'm aware that these options aren't very satisfying. The challenge is that it is really hard for an Open Source project to do integration tests with Oracle, since even downloading a legal Oracle JDBC driver from a public CI build is a nightmare, let alone a database.

    A coworker sent me this image when we were discussing the situation:

    But we don't give up, proper support will be added.

    0 讨论(0)
提交回复
热议问题