Joomla Popin Window by DART Creations

Sponsors

JBoss Books

Support this site buying books here

Merry Xmas

Banner

Designed by:
SiteGround web hosting Joomla Templates
How to lazy load your Entity Beans relations ? PDF Print E-mail
Written by Mark S.   
Wednesday, 19 November 2008 10:25
JBoss recipe of the day
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
Comments
Search
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Valid XHTML and CSS.

Unless stated, all the contents of this site is licensed under
Banner