Hi all,

is there a way to use output variables in stored procedures in OpenJPA? I
have a stored procedure called calcutaleTax (subtotal IN, taxamount OUT)
that I use to calculate the tax for an order. subtotal is an input argument,
and taxamount is an output argument.

I did a few experiments, but didn't manage to get the taxamount value. This
is what I currently have, but the value is not being assigned to "tax":
    private double calculateTaxJPA(double subtotal){
        EntityManager em = DatabaseUtil.getEntityManager();
        double taxamount = 0;
        Query q = em.createQuery("Call JDBC_SC.CALCULATETAX(?,?)");
        q.setParameter(1, subtotal);
        q.setParameter(2, taxamount);
        q.executeUpdate();
        return taxamount;
    }


So, this is all I was able to think of. Does anyone know how can I achieve
my needs? From a JDBC perspective, you need a CallableStatement in order to
call a stored procedure instead of a regular Statement or PreparedStatement.
However, CallableStatement has the execute() method, not present in the
javax.persistence.Query class.

If anybody has any ideas, please let me know :-)


Second question: @Ids that aren't persisted.
>From my understanding, even if I don't declare an @Id annotation in a class,
OpenJPA assigns an Id variable to that class and tries to insert into the
database. This caused some exceptions on my app, because I didn't have Id
column in the database. Is it possible to have a transient ID so that
OpenJPA has different IDs for all materialized java objects, but then it
discards that information when storing it in the database. As an example, I
have the PorderItem class, representing an item in a purchase order, and it
goes like this:

@Entity
@Table(name="PORDER_ITEM", schema="JPA_SC")
public class PorderItem {

    protected int poid; //purchaseorder ID
    protected String pid; //product ID
    protected int cid; //customer ID
    protected int poqty; // quantity
    protected String postatus;
    protected String podate;

    public PorderItem(){
    }
 .........
}


How can I get OpenJPA to store only these fields without inserting an extra
ID column? Note that I cannot use a composite ID with several variables,
because it is possible to have repeated entries.

Thanks all! Hope you can answer my questions!

Regards,
Vitor Rodrigues

Reply via email to