我无法通过在复合可嵌入键表上的选择在一次调用中检索这两个属性。我先抓计数,然后分页。整个站点的其他地方都在使用相同的逻辑。我在查询中收到以下错误。在这里真的迷路了。
java.sql.SQLSyntaxErrorException: ORA-00904: "U3_"."ID": 无效标识符
select
count(*) as y0_
from
TEST.USERBADGES this_
where
u3_.ID=?
Hibernate:
select
count(*) as y0_
from
TEST.USERBADGES this_
where
u3_.ID=?
Criteria criteria = userBadgeRepository.getCritieria();
criteria.createCriteria("userBadgePK", "ub", 1);
criteria.createCriteria("ub.badge", "b", 1);
criteria.createCriteria("ub.user", "u", 1);
用户徽章.java
@Entity
@Table(name = "USERBADGES", schema = "TEST")
@SuppressWarnings("serial")
@AssociationOverrides({
@AssociationOverride(name = "userBadgesPK.user", joinColumns = @JoinColumn(name = "userid")),
@AssociationOverride(name = "userBadgesPK.badge", joinColumns = @JoinColumn(name = "badgeid"))
})
public class UserBadge implements Serializable {
/**
* Primary key
*/
private UserBadgePK userBadgesPK = new UserBadgePK();
/**
* Attribute visible.
*/
private Long visible;
/**
* Attribute datecreated.
*/
private Date dateCreated;
/**
* Get the primary key
*/
@Basic
@EmbeddedId
public UserBadgePK getUserBadgePK() {
return this.userBadgesPK;
}
/**
* set the primary key
*/
public void setUserBadgePK(UserBadgePK userBadgesPK) {
this.userBadgesPK = userBadgesPK;
}
/**
* get users
*/
@Transient
public User getUser() {
return this.getUserBadgePK().user;
}
/**
* set users
*/
public void setUser(User user) {
getUserBadgePK().setUser(user);
}
/**
* get badges
*/
@Transient
public Badge getBadge() {
return getUserBadgePK().badge;
}
/**
* set badges
*/
public void setBadge(Badge badge) {
getUserBadgePK().setBadge(badge);
}
/**
* @return visible
*/
@Basic
@Column(name = "VISIBLE")
public Long getVisible() {
return visible;
}
/**
* @param visible new value for visible
*/
public void setVisible(Long visible) {
this.visible = visible;
}
/**
* @return datecreated
*/
@Basic
@Column(name = "DATECREATED")
public Date getDateCreated() {
return dateCreated;
}
/**
* @param datecreated new value for datecreated
*/
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserBadge that = (UserBadge) o;
if (getUserBadgePK() != null ? !getUserBadgePK().equals(that.getUserBadgePK()) : that.getUserBadgePK() != null) return false;
return true;
}
public int hashCode() {
return (getUserBadgePK() != null ? getUserBadgePK().hashCode() : 0);
}
@SuppressWarnings("serial")
@Embeddable
public static class UserBadgePK implements Serializable {
/**
* Attribute users
*/
private User user;
/**
* Attribute badges
*/
private Badge badge;
/**
* get users
*/
@ManyToOne(fetch=FetchType.EAGER)
public User getUser() {
return this.user;
}
/**
* set users
*/
public void setUser(User user) {
this.user = user;
}
/**
* get badges
*/
@ManyToOne(fetch=FetchType.EAGER)
public Badge getBadge() {
return this.badge;
}
/**
* set badges
*/
public void setBadge(Badge badge) {
this.badge = badge;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserBadgePK that = (UserBadgePK) o;
if (badge != null ? !badge.equals(that.badge) : that.badge != null) return false;
if (user != null ? !user.equals(that.user) : that.user != null)
return false;
return true;
}
@Override
public int hashCode() {
int result;
result = (badge != null ? badge.hashCode() : 0);
result = 31 * result + (user != null ? user.hashCode() : 0);
return result;
}
}
}