i am trying to extract a list of objects from database from entity (table) StudySeries:
@Entity
@Table(name="StudySeries", uniqueConstraints = {
@UniqueConstraint(columnNames = "SeriesInstanceUID")})
public class StudySeries implements Serializable {
...
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "SeId", unique = true, nullable = false)
private Long seId;
@Column(name="SeriesInstanceUID", unique=true, nullable = false)
private String seriesInstanceUID;
...
@ManyToOne
@JoinColumn(name = "StId", referencedColumnName="StId")
private StudyDetails studyDetails;
...
}
This entity is N-1 joined with StudyDetails (on StudyDetails has many StudySeries):
@Entity
@Table(name="StudyDetails", uniqueConstraints = @UniqueConstraint(columnNames = "StudyInstanceUID"))
public class StudyDetails implements Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name="StId", unique = true, nullable = false)
private Long stId;
@Column(name="StudyInstanceUID", unique=true, nullable = false)
private String studyInstanceUID;
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "studyDetails", cascade = CascadeType.ALL)
private Set<StudySeries> studySeries = new HashSet<StudySeries>(0);
...
}
In my StudySeriesDAOImpl() i am trying to:
@Override
public List<StudySeries> getStudySeriesObjectsByStudyId(Long stId) {
List<StudySeries> results=new ArrayList<>();
Session s=HibernateUtil.openSession();
s.beginTransaction();
String hql = "from StudySeries E where E.studyDetails.stId = stId";
Query query = s.createQuery(hql);
query.setParameter("stId", stId);
results = query.list();
s.getTransaction().commit();
s.close();
log.info(">>>>> list size: " + results.size());
return results;
}
I have also tried the hql query as:
String hql = "from StudySeries E where E.stId = stId";
However i am getting:
org.hibernate.QueryParameterException: could not locate named parameter [stId]
at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:100) at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:100)
at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:106)
at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:466)
at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:436)
at com.npap.dao.StudySeriesDAOImpl.getStudySeriesObjectsByStudyId(StudySeriesDAOImpl.java:239)
Any ideas what is wrong?
Aucun commentaire:
Enregistrer un commentaire