Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 334184

Summary: Using @Index annotation on an entity field fails on PostGres (looks like setField not being called), on getter fails to generate index
Product: z_Archived Reporter: wayne townsend-merino <townsendmerino>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: syvalta, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard: postgresql

Description wayne townsend-merino CLA 2011-01-12 19:37:02 EST
Build Identifier: 2.2

@Entity
@Table(name = "dt_samples", schema = "kb")
public class Sample extends AbstractKbEntity {
    private static final long serialVersionUID = 1L;
    
    @Column(length = 50) 
    @Index
    private String timeUnits;

generates:

[EL Info]: 2011-01-12 16:31:52.929--ServerSession(139291418)--EclipseLink, version: Eclipse Persistence Services - 2.2.0.qualifier
[EL Info]: 2011-01-12 16:31:53.08--ServerSession(139291418)--file:/Users/tmAir/LBL/work_kb/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/kbweb/WEB-INF/classes/_kbweb login successful
[EL Warning]: 2011-01-12 16:31:53.246--ServerSession(139291418)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: index "index_dt_samples_" does not exist
Error Code: 0
Call: DROP INDEX INDEX_dt_samples_
Query: DataModifyQuery(sql="DROP INDEX INDEX_dt_samples_")
[EL Warning]: 2011-01-12 16:31:53.306--ServerSession(139291418)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
  Position: 50
Error Code: 0
Call: CREATE INDEX INDEX_dt_samples_ ON kb.dt_samples ()
Query: DataModifyQuery(sql="CREATE INDEX INDEX_dt_samples_ ON kb.dt_samples ()")

-------

Also, using this:


    @Index
    public String getTimeUnits() {
        return timeUnits;
    }

fails to generate an index in the DDL



Reproducible: Always

Steps to Reproduce:
1.Use @Index annotation on a field or getter
2.
3.
Comment 1 Tom Ware CLA 2011-01-26 14:51:41 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 2 Sei Syvalta CLA 2011-03-02 05:53:22 EST
Occurs also with hsql 2.0.0.

[EL Warning]: 2011-03-02 12:46:45.715--ServerSession(1006157069)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: unexpected token: )
Error Code: -5581
Call: CREATE INDEX INDEX_FOO_ ON FOO ()
Query: DataModifyQuery(sql="CREATE INDEX INDEX_FOO_ ON FOO ()")
Comment 3 Sei Syvalta CLA 2011-03-02 06:09:59 EST
It seems SQL generated for Oracle fails too:

Error: ORA-00936: missing expression

SQLState:  42000
ErrorCode: 936
Position: 256
Error occured in:
CREATE INDEX INDEX_FOO_ ON FOO ()
Comment 4 Sei Syvalta CLA 2011-03-02 06:31:52 EST
One more addition: it seems that the default field name causes the problem.

So this works:
@Index
@Column(name="something")
int something;

And this too:
@Index(columnNames="something")
int something;

But the most common one with default name does not:
@Index
int something;

Seems to apply for all platforms.
Comment 5 Sei Syvalta CLA 2011-10-19 07:35:04 EDT
This seem to be working in 2.3.0.
Comment 6 Tom Ware CLA 2011-10-19 08:20:15 EDT
Setting to fixed based on above comment.
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:08:16 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink