These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Annotation '@Loader' annotation.
PostPosted: Thu May 14, 2009 10:49 am 
Newbie

Joined: Thu May 14, 2009 10:34 am
Posts: 11
Hi all,
I have query regarding usage of @Loader attribute. I just don't understand how to use it. I tried all possible ways to make it work, but no success. Can anybody Please have look at this code and let me know what is wrong.
I am using Seam Framework 2.1.1 for creating my application.
Code:

@Entity
@Table(name = "employee")
@NamedNativeQuery(name="employee", query="Select * from employee where roleId > 3", resultClass = Employee.class)
@Loader(namedQuery="employee")
public class Employee {
   @Id
   @GeneratedValue(strategy = GenerationType.TABLE)
   @Column(name = "empId")
   private int id;

   @Column(name = "empName")
   private String name;

   @Column(name = "salary")
   private int salary;

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "deptId")
   private Department dept;

   @OneToMany(fetch = FetchType.LAZY)
   @JoinTable(name = "emp_proj", joinColumns = @JoinColumn(name = "empId"), inverseJoinColumns = @JoinColumn(name = "id"))
   private List<EmpProject> emp_proj;

   @Column(name = "roleId")
   @Enumerated(EnumType.ORDINAL)
   private Role role;

   public Role getRole() {
      return role;
   }

   public void setRole(Role role) {
      this.role = role;
   }

   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public int getSalary() {
      return salary;
   }

   public void setSalary(int salary) {
      this.salary = salary;
   }

   public Department getDept() {
      return dept;
   }

   public void setDept(Department dept) {
      this.dept = dept;
   }

   public List<EmpProject> getEmp_proj() {
      return emp_proj;
   }

   public void setEmp_proj(List<EmpProject> emp_proj) {
      this.emp_proj = emp_proj;
   }
}


And I am getting list of Employee as
entityManager.createQuery("from Employee");

Is here anything wrong?
[/color]

Please help me. :)


Top
 Profile  
 
 Post subject: Re: Hibernate Annotation '@Loader' annotation.
PostPosted: Fri May 15, 2009 3:56 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Your custom loader is used when loading objects using find(). In your case you are using an HQL-Query to query for entities, so this HQL Query is used.

Take a look at filters, I think these will fit your needs.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Hibernate Annotation '@Loader' annotation.
PostPosted: Sun May 17, 2009 5:49 am 
Newbie

Joined: Thu May 14, 2009 10:34 am
Posts: 11
hmmm! Ok! I thought it will fetch the data as per loader annotation.

Thank you so much! for your response.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.