Question

On the language that I know, RPG... You can use multiple keys and find retrieve the values of the record.

Like for table. I can select keys lolo and apple to retrieve the value of sex witch is F. Howerver I could not find some functionality that is like this in OPENJPA.. find() can only use one key? Is there something like find(names.class,:"LOLO","Apple") where keys are F_NAME and L_NAME?

Names
F_NAME   L_NAME   Sex
LOLO     Apple     F

Ben      Coke      M

While reading jpa, usually the table has P_ID

P_ID     F_NAME  L_NAME  Sex
1        LOLO     Apple   F 
2        Ben      Coke    M

To retrieve the record lolo apple, i need to use this code..

Names name = em.find(Names.class, 1);

How will you know the sex if the given value is F_NAME? and L_NAME? In SQL you can just say select * from Names where F_NAME = Lolo , L_NAME = "Apple" and it will output

P_ID     F_NAME  L_NAME  Sex
1        LOLO     Apple   F 

From that you can say that Sex = F. Like i want to know if lolo apple is male or female, I will search lolo apple on the database... not P_ID = 1. How would i konw what is the P_ID of Lolo Apple.

Hopefully you get what I mean.. Thanks.

Or maybe in another part of the equation, on JPA, how to you retrieve the record to be updated while not knowing yet the P_ID (Primary key) like you only know the first name and last name?

Was it helpful?

Solution

If you look at the OpenJPA documentation it defines a JPA Query Language [JPQL]. Wouldn't that be the place to start?


UPDATE

If you want to specify several key values, why not just specify them in the WHERE clause in JPQL, like you would do in SQL.

SELECT ...
  WHERE colX = val1 and colY = val2 and colZ = val3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top