Hi, I have the following entities (I omitted the getters and setters)
Code:
@Entity
@NamedQueries( {
@NamedQuery(name = "getClassificationStatistics",
query = "select c.classification as label, count(*) as numberOfPaper " +
"from Classification c " +
"where c.article.year between :firstYear and :lastYear " +
"group by c.classification " +
"order by c.classification"),
@NamedQuery(name = "getClassificationFromArticle",
query = "from Classification c where c.article = :article") })
public class Classification {
@Id
@GeneratedValue
private long identifier;
@OneToOne
Article article;
String classification;
and
Code:
@Entity
@Table(name = "ARTICLES")
public class Article {
@Id
@GeneratedValue
@Column(name = "ArticleId")
private long identifier;
private String title;
@Type(type = "text")
private String articleAbstract;
private int year;
@Lob
private byte[] fullTextPdf;
@ManyToOne
private Journal journal;
@ManyToMany
@JoinTable(name = "Article_Author", joinColumns = { @JoinColumn(name = "ArticleId") }, inverseJoinColumns = { @JoinColumn(name = "AuthorId") })
private List<Author> authors = new Vector<Author>();
My issue is with the getClassificationStatistics that takes long time to be executed. Is there any way to add indexes to make it faster?
Moreover I am not sure if the relation between the entities I defined is the right one. So far I just annotated with a @OneToOne, without telling that in Classification the Article object has to be a foreign key. Is that right or should I modify something?