Sponsors
JBoss Books
Support this site buying books hereMerry Xmas
| How to lazy load your Entity Beans relations ? |
|
|
|
| Written by Mark S. | |||||
| Wednesday, 19 November 2008 10:25 | |||||
|
You can specify in your annotations the fetch strategy (fetch = FetchType.LAZY) Example:
@Entity
@Table(name = "PET")
public class Pet implements Serializable {
private long id;
private Zoo zoo;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="ZOO_ID")
public Zoo getZoo() {
return zoo;
}
public void setZoo(Zoo zoo) {
this.zoo = zoo;
}
}
@Entity
@Table(name = "ZOO")
public class Zoo implements Serializable {
private long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
JBoss.org Search
Custom Search
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |



