You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by vivek <vi...@geojit.com> on 2007/10/18 08:30:24 UTC

Regarding Fetch groups in OpenJPA

Problem :Regarding Fetch groups in OpenJPA.

 

public class EmployeePK {

 

@Column(name = "EmployeeID", nullable = false)

 

private long employeeID;

 

@Column(name = "SerialNo", nullable = false)

 

private int serialNo;

 

}

 

public class Employee {

 

@EmbeddedId

 

protected EmployeePK employeePK;

 

private String firstName;

 

private String lastName;

 

@ManyToOne private Department dept;

 

}

 

public class Department {

 

@Id private int id;

 

private String departmentName;

 

}

 

 

This is the sample scenario.

There are 3 entity classes, one is the primary key class.

Here normally if i am not using fetch group feature in OpenJPA, during
retrieval all fields will retrieved from employee and department tables.

But i need some fields from both the tables to be fetched first.

By seeing fetch group documentation, i couldnt get a full idea of how to
configure fetch groups for related entities.

So please give a sample configuration for the above scenario.


Re: Regarding Fetch groups in OpenJPA

Posted by Kevin Sutter <kw...@gmail.com>.
Vivek,
There are a couple of examples in the OpenJPA test bucket:

org.apache.openjpa.persistence.fetchgroups.FGEmployee.java
org.apache.openjpa.persistence.fetchgroupsFGManager.java

If you don't have the source downloaded, you can view it via the svn viewer:

http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/FGEmployee.java?view=markup
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/FGManager.java?view=markup

Kevin

On 10/18/07, vivek <vi...@geojit.com> wrote:
>
> Problem :Regarding Fetch groups in OpenJPA.
>
>
>
> public class EmployeePK {
>
>
>
> @Column(name = "EmployeeID", nullable = false)
>
>
>
> private long employeeID;
>
>
>
> @Column(name = "SerialNo", nullable = false)
>
>
>
> private int serialNo;
>
>
>
> }
>
>
>
> public class Employee {
>
>
>
> @EmbeddedId
>
>
>
> protected EmployeePK employeePK;
>
>
>
> private String firstName;
>
>
>
> private String lastName;
>
>
>
> @ManyToOne private Department dept;
>
>
>
> }
>
>
>
> public class Department {
>
>
>
> @Id private int id;
>
>
>
> private String departmentName;
>
>
>
> }
>
>
>
>
>
> This is the sample scenario.
>
> There are 3 entity classes, one is the primary key class.
>
> Here normally if i am not using fetch group feature in OpenJPA, during
> retrieval all fields will retrieved from employee and department tables.
>
> But i need some fields from both the tables to be fetched first.
>
> By seeing fetch group documentation, i couldnt get a full idea of how to
> configure fetch groups for related entities.
>
> So please give a sample configuration for the above scenario.
>
>

RE: Regarding Fetch groups in OpenJPA

Posted by Pinaki Poddar <pp...@bea.com>.
Hi,
You can define a fetch group named 'X' in Employee as well as
Department. 
Include fields of Employee and Department in Fetch Groups 'X' in
respective classes.
Now activating 'X' will result in fetching the fields of both the
classes. 
Primary key fields are fetched always.
  

Pinaki Poddar
972.834.2865
 

>-----Original Message-----
>From: vivek [mailto:vivekmv@geojit.com] 
>Sent: Thursday, October 18, 2007 1:30 AM
>To: dev@openjpa.apache.org
>Subject: Regarding Fetch groups in OpenJPA
>
>Problem :Regarding Fetch groups in OpenJPA.
>
> 
>
>public class EmployeePK {
>
> 
>
>@Column(name = "EmployeeID", nullable = false)
>
> 
>
>private long employeeID;
>
> 
>
>@Column(name = "SerialNo", nullable = false)
>
> 
>
>private int serialNo;
>
> 
>
>}
>
> 
>
>public class Employee {
>
> 
>
>@EmbeddedId
>
> 
>
>protected EmployeePK employeePK;
>
> 
>
>private String firstName;
>
> 
>
>private String lastName;
>
> 
>
>@ManyToOne private Department dept;
>
> 
>
>}
>
> 
>
>public class Department {
>
> 
>
>@Id private int id;
>
> 
>
>private String departmentName;
>
> 
>
>}
>
> 
>
> 
>
>This is the sample scenario.
>
>There are 3 entity classes, one is the primary key class.
>
>Here normally if i am not using fetch group feature in 
>OpenJPA, during retrieval all fields will retrieved from 
>employee and department tables.
>
>But i need some fields from both the tables to be fetched first.
>
>By seeing fetch group documentation, i couldnt get a full idea 
>of how to configure fetch groups for related entities.
>
>So please give a sample configuration for the above scenario.
>
>

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.