9
Son playpartework (2.0.4) sürümü ve Ebean ORM ile çalışıyorum.Ebean - Yabancı anahtarları içeren birleşik birincil anahtar.
@Entity
public class UserGroup extends Model {
private static final long serialVersionUID = 1L;
@EmbeddedId
public UserGroupPK pk;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", insertable = false, updatable = false)
public User user;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_id", insertable = false, updatable = false)
public Group group;
}
@Embeddable
public class UserGroupPK implements Serializable{
private static final long serialVersionUID = 1L;
public Long userId;
public Long groupId;
public UserGroupPK(Long userId, Long groupId) {
this.userId = userId;
this.groupId = groupId;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final UserGroupPK other = (UserGroupPK) obj;
if ((this.userId == null) ? (other.userId != null) : !this.userId.equals(other.userId)) {
return false;
}
if ((this.groupId == null) ? (other.groupId != null) : !this.groupId.equals(other.groupId)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 89 * hash + (this.userId != null ? this.userId.hashCode() : 0);
hash = 89 * hash + (this.groupId != null ? this.groupId.hashCode() : 0);
return hash;
}
}
sağ sizin için mi: İşte benim basitleştirilmiş db şema
böyle, benim varlık modelleri oluşturmak istiyoruzTABLENAME (FIELD_NAME (, ...))
User (id)
Group (id)
UserGroup (user_id, group_id, is_active)
olduğunu. Ve eğer bu ara tablo için uygunsa, Kullanıcı ve Grup varlığından ne haber? Şimdiden teşekkürler.
Haritalama bilge, bu sadece iyi. Ama bu sınıf için bir bulucu yapmanın iyi şanslar. Ebeans'ı normalde kompozit anahtarlarla çalışmayı başaramadım. – kaqqao