0

I've been already following a couple of solutions here and there but still not managing to make it work.

I've got and Oracle database and this Entity:

@Entity(name = "NGRAM")
public class Ngram
{
    @Id
    @JsonProperty("ngram")
    private String ngram;

    @JsonProperty("frequency")
    @Column(name = "frequency")
    private int frequency;

    @JsonProperty("occurrences")
    @Column(name = "occurrences")
    private int occurrences;

And I was trying to add this @SQLInsert query:

@SQLInsert(sql="INSERT INTO NGRAM
                    (ngram, frequency, occurrences) 
                    VALUES (?, ?, ?) 
                    ON DUPLICATE KEY UPDATE 
                        frequency = frequency + 1,
                        occurrences = occurrences + VALUES(occurences);")

But I got this error using a few different solutions:

2019-01-28 16:35:22 DEBUG org.hibernate.SQL - INSERT INTO NGRAM(ngram, frequency, occurrences) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE frequency = frequency + 1,  occurrences = occurrences + VALUES(occurences);
2019-01-28 16:35:22 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - [1]
2019-01-28 16:35:22 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [INTEGER] - [2]
2019-01-28 16:35:22 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [since constraints]
2019-01-28 16:35:22 WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 933, SQLState: 42000
2019-01-28 16:35:22 ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-00933: SQL command not properly ended

It's my Query wrong?

I've read from here that updating/inserting same row twice in the same transactio could lead to problems and I'm using Repo.saveAll to improve speed a bit, but as far as I can tell the keys should be unique since I'm getting them from a map having a Map(String, Integer).

2
  • 1
    Does Oracle even support INSERT INTO .... VALUES (...) ON DUPLICATE KEY UPDATE ... syntax? it would seem not: stackoverflow.com/questions/15161578/… Commented Jan 28, 2019 at 15:56
  • @AlanHay Truth be said, that's something I hadn't look at, I kinda expected Oracle to be comformant at this level :S Commented Jan 28, 2019 at 15:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.