0

I retrived the Java Bean Properties using reflection.But I am unable to get Collections,Custom Object from Orignal Bean.For Example,

@Entity
@Table(name = "ucms_user_tbl")
public class Employee {

@Id
@Column(name="employee_no")
private int employeeno;
@Column(name="Employee_name")
private String employeeName,
//one-to-Many
@OneToMany(mappedBy="EmpDtl")
private List<EmpDtl> dtlList=new ArrayList<EmpDtl>();
@ManyToOne
@JoinColumn(name="status_id")
//Many-to-One
private EMPStatus empStatus;


}

I retrived the employeeno,employeename using reflection.But i unable to find out dtlList,empStatus properties.

for(Method metd:method){
    Annotation[] annotations = m.getAnnotations();
         for(Annotation annotation : annotations){          
                  if(annotation instanceof Column){
                Column myAnnotation = (Column) annotation;
                name=myAnnotation.name();

                   }
         }
}
gaborsch
  • 15,408
  • 6
  • 37
  • 48
tech2504
  • 947
  • 4
  • 19
  • 34
  • 2
    Where do annotations come into it? You haven't got any in your code. Please post your _real_ code. – Boris the Spider Apr 07 '13 at 17:33
  • 1
    More importantly, why do you need reflection? Aren't you trying to reach some functionality the wrong way? If you know what you're doing why don't you use `Class#getDeclaredField` method? – skuntsel Apr 07 '13 at 17:39
  • Are you trying to introspect JPA `Entity` instances? That won't go. – gaborsch Apr 07 '13 at 17:41
  • Yes.I using JPA Entity. – tech2504 Apr 07 '13 at 17:45
  • JPA Entities should be handled only via the declared methods. The internal representation is not public, and depends on the JPA provider (Hibernate or Eclipselink). So, you *think* that you have an `Employee` instance, but you're wrong. Those instances are managed by the JPA provider, especially the references to other JPA entities and collections (you have both in your example). Try do debug, and peek inside an instance. – gaborsch Apr 07 '13 at 17:49
  • I requried database field names and relevent properties of JPA Entity.I implemneting based on this url (http://stackoverflow.com/questions/2921451/get-column-name-in-jpa).what is best mehtodolgoy to retrive properties with values of JPA Entity? – tech2504 Apr 07 '13 at 17:55

0 Answers0