2

I create an entity object, and annotated it with @Index annotation. Application works, but in database not exist index I want. I tried both JPA and Hibernate annotations with no luck. This class placed in Spring boot 1.3.3.RELEASE application. In Maven dependencies I see hibernate-core-4.3.11.Final.jar and it maps to PostgreSQL 9.4.5. I tried different values for spring.jpa.hibernate.ddl-auto in application.properties file, like create, create-drop, update and even removed tables from database myself.

Please help: How to make application create index using annotations?

Update

I played with annotations and indexes created with same config. I cannot understand what differs. I only find that after I stop my application, and tables created in database it takes some time to see indexes update in pgAdmin. It looks like some cache update or so. Also I find that cannot create index with same name for different tables. Still cannot get what happen.

Update

Here entity class

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.jsoup.nodes.Element;

@Entity
@Table(indexes = { @Index(name = "job_id_idx", columnList = "job_id")})
public class JobLifeTime {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)   
    private Long code;

    @Column(name="job_id", length=24)

    private String targetJobCode;
    @ManyToOne()
    private ScraperTask scraperTask;
    @Column(name="salary_low")
    private Integer salaryMin;
    @Column(name="salary_high")
    private Integer salaryMax;
    @Column(name="scrape_timestamp")
    private Date scrapeTimestamp;
    @Column(name="remove_timestamp")
    private Date removeTimestamp;

    public JobLifeTime(){}

    //getters and setters ...
}
7
  • I noticed above that you said Application.properties. Was that just a typo? The file should be named application.properties (notice the lowercase) and it must be placed under src/main/resources for Spring to auto-recognise it Commented Apr 21, 2016 at 5:14
  • Yes right - lower case. Application see this file and take config from it. I just miss here when write. Will edit a post. Commented Apr 21, 2016 at 5:19
  • Maybe this helps stackoverflow.com/questions/22816817/hibernate-create-index Commented Apr 21, 2016 at 5:37
  • Are you using JPA 2.1? Commented Apr 21, 2016 at 5:51
  • How should I know JPA version? Commented Apr 21, 2016 at 6:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.