1
我使用Hibernate3的生成和我有與下列集合的實體:錯誤查詢與@OrderBy註釋
@ManyToMany
@JoinTable(name = "buys_publishers", [email protected](name="buy_id", referencedColumnName = "buy_id"), [email protected](name = "publisher_id", referencedColumnName = "publisher_id"))
@OrderBy("name")
private List<Publisher> publishers;
(讀取和級聯減速省略)
目標實體(出版者)從繼承一個擁有@orderby被激活的「name」屬性的實體。
這裏的目標實體:
@Entity
@Table(name="publishers")
@PrimaryKeyJoinColumn(name="account_id")
public class Publisher extends Account{
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name = "publisher_id")
private Long publisherId;
public Long getPublisherId() {
return publisherId;
}
public void setPublisherId(Long publisherId) {
this.publisherId = publisherId;
}
}
和超類:
@Entity
@Table(name="accounts")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Account implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name="id",unique=true, nullable=false)
@GeneratedValue(strategy = IDENTITY)
private long id;
@Column(name = "name")
private String name;
@Column(name = "account_type")
@Enumerated(EnumType.ORDINAL)
private AccountType accountType;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public AccountType getAccountType() {
return accountType;
}
public void setAccountType(AccountType accountType) {
this.accountType = accountType;
}
}
,Hibernate對生成的查詢是:
select publishers0_.buy_id as buy1_1_, publishers0_.publisher_id as publisher2_1_, publisher1_.account_id as id6_0_, publisher1_1_.account_type as account2_6_0_, publisher1_1_.name as name6_0_, publisher1_.publisher_id as publisher1_18_0_ from buys_publishers publishers0_ left outer join publishers publisher1_ on publishers0_.publisher_id=publisher1_.publisher_id left outer join accounts publisher1_1_ on publisher1_.account_id=publisher1_1_.id where publishers0_.buy_id=? order by accounts.name asc
它是從查詢清楚,順序應該在publisher1_1_,我做錯了什麼或這是一個錯誤?
謝謝。