我有一個USER表與許多其他表,通常,星型拓撲關聯。休眠與JPA註釋問題 - 懶惰的對象
像這樣:
@Entity
@Table(name = "user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "user_USERID_GENERATOR", sequenceName = "user_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userR_USERID_GENERATOR")
@Column(name = "user_id")
private long userId;
@Basic
@Column(name = "password_hex")
private String password;
@Basic
@Column(name = "language")
private String language;
@Temporal(TemporalType.DATE)
private Date created;
@Temporal(TemporalType.DATE)
private Date modyfied;
@Basic
@Column(name = "first_name")
private String firstName;
@Basic
@Column(name = "last_name")
private String lastName;
@Basic
@Column(name = "passport")
private String passport;
@Basic
@Column(name = "pesel")
private String pesel;
@Basic
@Column(name = "phone_nr1")
private String phoneNr1;
@Basic
@Column(name = "phone_nr2")
private String phoneNr2;
@Column(name = "hash")
private String hash;
// uni-directional many-to-one association to DictUserType
@ManyToOne
@JoinColumn(name = "status")
private DictUserStatus status;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = { CascadeType.ALL })
private Set<Email> emails = new HashSet<Email>(0);
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = { CascadeType.ALL })
private Set<Address> address = new HashSet<Address>(0);
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = { CascadeType.ALL })
private Set<ArchivePasswords> archivePasswords = new HashSet<ArchivePasswords>(
0);
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = { CascadeType.ALL })
private Set<HostsWhitelist> hostsWhitelist = new HashSet<HostsWhitelist>(0);
.... 我有一個DAO層,由用戶ID搜索的方法。
public User findUser(long userId) throws UserNotFoundException {
User user = userDao.findUser(userId);
if (user == null) {
throw new UserNotFoundException("Could not find user with id = "
+ userId);
}
return user;
}
爲什麼懶取指不起作用?
你會得到什麼例外?你遇到異常時你想做什麼? – jny 2011-02-23 15:06:53
你可以發佈相關的代碼和例外嗎? – jny 2011-02-23 15:57:58