[jboss-user] [EJB 3.0] - How to retrieve foreign key instead of the object (want no l

lpmon do-not-reply at jboss.com
Tue Dec 4 18:26:26 EST 2007


Goal: ability to retrieve the foreign key without loading the related object/table row.

Scenario:

Entity bean contains a related entity bean.

@Entity
class Unit{ // Unit table

// what kind of unit
Model model;   // related object in Model table, related column is modelId

In the Unit table there is a column called modelId to point to the row in the Model table.  If I want this key value I can use

Unit u = .... somehow get it with EntityManager or whatever;

int modelId = u.getModel().getId(); // causes read of Model table!

Issue - this will cause a read of the model row from the DB (won't it, as in lazy loading will perform a JIT read)

I only need the modelId which is in the Unit table.  It seems there should be a way to do this and not load the related object. 

One can do this with EJBQL by using the reserved  Class.id syntax.  How can I take advantage of that in the ORM classes?

I used a simple example.  In my app if I can accomplish this I can easily avoid a lot of unwanted DB fetches.







View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110371#4110371

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110371



More information about the jboss-user mailing list