I’m using the following code to retrieve my data
Criteria cr = session.createCriteria( JobProcess.class );
cr.createAlias("sendMarcs", "sm");
cr.addOrder( Order.desc( "processedTime") );
cr.addOrder( Order.asc( "sm.ats" ) );
It returns all the data, but all the data appears multiple times, returning a list of size 673 when it should be a list of size 99. I have no idea why it’s happening.
And yes, I’ve looked at the SQL that hibernate is using and it’s correct.
Also, if I remove the alias and its order, then the data appears as expected. Not multiplied, but not sorted.
JobProcess.java
@Entity
@Table(name = "jobprocess")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class JobProcess {
@Id
@GeneratedValue
private Long id;
@Basic(optional = false)
@Column(length = 20, name="customerid")
private String customerId;
@Basic(optional=false)
@Column(length = 100)
private String ATS;
@Basic(optional=true)
@Temporal(TemporalType.TIMESTAMP)
@Column(name="timeprocessed")
private java.util.Date processedTime;
@Basic(optional=false)
@Column(length = 1)
private String state;
@Column(length = 300)
private String notes;
@Basic(optional = false)
private long nos;
@OneToMany(mappedBy = "jobprocessid")
private Set<SendMarc> sendMarcs = new HashSet<SendMarc>();
// getters and setters
}
SendMarc.java
@Entity
@Table( name = "sendmarc" )
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
public class SendMarc
{
@Id
@GeneratedValue
private BigInteger id;
@Basic( optional = true )
private BigInteger marcfileid;
@Basic( optional = false )
private long jobprocessid;
@Basic( optional = false )
@Column( length = 50 )
private String ats;
// getters and setters
}
It’s returning one object per retrieved row, as a HQL query without distinct would do. WIth a Criteria, you must use