users@glassfish.java.net

EJB3 get last Persisted Entity

From: <glassfish_at_javadesktop.org>
Date: Tue, 05 Feb 2008 07:39:57 PST

I am trying to get the last entity i persist, so i can get "THE ID" of the resent created Entity.
 So I can use it to get other elements.
I tried:

        [b]public int crearSucursal(String rutEmpresa) {
                int resultado;
                try {
                        
                        Sucursal sucursal = new Sucursal();
                        sucursal.setRutEmpresa(Integer.parseInt(rutEmpresa));
                        em.persist(sucursal);
                        resultado = sucursal.getIdSucursal();
                        return resultado;
                } catch (Exception e) {

                        error.imprimirError(e, "Error al Crear LA Sucursal");
                        return -1;
                }[/b]


But I cant get the id of the persisted Entity. !!! it keep getting zero as a result. Can somebody help me with this ?
[Message sent by forum member 'naitus' (naitus)]

http://forums.java.net/jive/thread.jspa?messageID=257499