Home > Hibernate

Example of @Target in Hibernate

May 29, 2013
@Target forces the entity field to return specified class. By default reflection returns the object of the class as return type. Suppose a field has a return type an interface but we want to use the implementation class. In that case @Target plays a role. Find the example how to use.
@Entity
@Table(name="lion")
public class Lion {
	@Id
	@Column(name = "id")
	private int id;

	@Embedded
	@Target(AnimalImpl.class)
	private Animal animal;
}
 
Animal is an interface and AnimalImpl is the class which implements Animal. The property animal has been annotated by @Target(AnimalImpl.class), so the field will return AnimalImpl.
comments powered by Disqus


Home    Core Java    Spring    Hibernate    Jquery    My Computer    News    Forum    Quiz    Interview Q & A     Maven     Eclipse IDE

Copyright ©2014 concretepage.com | All rights reserved |Privacy