I am developping a JPA, EJB and JSF 2.0 web app. I persist an entity PedidoUsuario and afetr it I want to get its PK in
the corresponding table ALMACEN.PEDIDO_USUARIO. To persist the entity I use an special EJB that calls another EJBs.
Here is the EJB,
The problem is in the method placeOrder(Usuario usuario, ShoppingCart cart) when I try to get the PK of the persisted PedidoUsuario.
For it I use an EJB that implements a StoredProcedureCall. Why? The reason why is that if I use JPQL, being the PK type of sequence
it returns me a wrong PK. So I guessed it could be resolved attacking the database directly.
Ok Jose, so you're using a sequence generator for your ID's. Could you test just some minimalist code if the entity is persisted, i.e.:If you invoke this code, you should see the automatically generated (using your sequence) ID printed in the console. If you don't than I guess it's something wrong with this sequence generator.
By the way - is this (assigning of an ID and reading it back) all what you want to achieve right now?
Jose Alvarez de Lara
Joined: May 10, 2008
>>By the way - is this (assigning of an ID and reading it back) all what you want to achieve right now?
Yes, that is all.
I do not understand why the sequence generator returns pu.getPedidousuario 106 value when the PK in the table Pedido_Usuario (ID_PEDIDOUSUARIO)
is 107 value. This is the reasson why I prefer to get it calling a SP or a Function. But even in those cases I get a NullPointer.
I am in conversation with James Sutherland from EclipseLink by the mailing list but all the help should be really appreciated.
The other one is calling a StoredFunctionCall that gets the last Id inserted in the database.
The estrange thing is that in both cases I get a value one unit less than the real Id (PK).
I mean if the inserted Id (PK) has value of ‘n’ I get in both cases ‘n-1’. And that is the
reason I am getting NullPointerException for the first inserting.
But one thing that I cannot understand is that if I execute the Function from inside an Oracle
management tool I get the correct value so there must be something wrong during the execution
of the EJBs.
Any suggestion about this issue should be really appreciated.