2

I would like to add indexing to my existing Entity, exacly on specific column. Following by documentation i wrote something like that:

1.first way
@Entity
@Table(name = "potatoe", schema = "mySchema")
public class Potatoe {
(...)
@Index(name = "knife", table = "potatoe", schema = "mySchema")
    private String origin;
(...)
}

2.second way
@Entity
@Table(name = "potatoe", schema = "mySchema")
@Index(name = "knife", columnNames = "origin", table = "potatoe", schema = "mySchema")
public class Potatoe {
(...)
    private String origin;
(...)
}

 3. third way(pure jpa)
    @Entity
    @Table(name = "potatoe", schema = "mySchema", indexes = {@javax.persistence.Index(name = "knife", columnList = "origin")})
    public class Potatoe {
    (...)
        private String origin;
    (...)
    }

But isnt working, the INDEX not created. And I always gotted exception:

Caused by: org.postgresql.util.PSQLException: ERROR: error in syntax or/in near "."

Query created by EclipseLink is

CREATE INDEX myschema.knife ON potatoe (ORIGIN)]]

and i dont know why he change the name of index. Why eclipseLink add schema with dot to name? I suppose that this "." in name of index makeing problem, but I don't know how to delete this.

I'am working on eclipselink ver 2.5.0 and postgresql ver 9.1-901.

edit// When i delete attribute "schema", eclipselink create properly query:

CREATE INDEX knife ON potatoe (ORIGIN)]]

but problem is that i must define schema because I have some. So without defined schema its a error about relation(relation not exisit). So its true, because my default relation isn't "myschema".

I check in Postgres and working query is like below but i dont know how to generate this:

CREATE INDEX knife ON myschema.potatoe (ORIGIN)

Someone have idea?

newOne
  • 679
  • 2
  • 9
  • 27
  • seems like a bug - index should not have schema name prepend, but the table should - all the way around – Vao Tsun Apr 12 '17 at 14:23
  • maybe try ```@Index(name = "knife", columnNames = "origin", table = "potatoe")``` ?.. – Vao Tsun Apr 12 '17 at 14:33
  • @Vao Tsun i try i think all kind of variations of ths annotation and all no works :/ – newOne Apr 12 '17 at 14:41
  • all with same error?.. – Vao Tsun Apr 12 '17 at 14:48
  • Not exacly, when I no define schema, the errror is "no relation to nameOfDatabase". Its appears because my default schema isnt "mySchema", otherwise error is the same. – newOne Apr 13 '17 at 06:19
  • try a monkey hack? `@Index(name = "knife", columnNames = "origin", table = "myschema.potatoe")` – Vao Tsun Apr 13 '17 at 07:12
  • I didnt think about it, its works :D Thank You :) I cant add "+" to your comment, maybe wrote this like a answer. – newOne Apr 13 '17 at 08:23
  • I made it an answer. Probably you should also write to EclipseLink support. This lack seems as serious limitation – Vao Tsun Apr 13 '17 at 08:27
  • Please check the spelling of your title: https://wiki.postgresql.org/wiki/Identity_Guidelines – Cœur Nov 13 '18 at 11:15

1 Answers1

0

I could not find indeed the schema defining for table in docs Try a monkey hack:

@Index(name = "knife", columnNames = "origin", table = "myschema.potatoe")
Vao Tsun
  • 47,234
  • 13
  • 100
  • 132