troubleshooting Question

How do you retrieve an auto increment key after persisting to the database.

Avatar of ethnarch
ethnarch asked on
JavaJava EE
8 Comments1 Solution1281 ViewsLast Modified:
I am using toplink in netbeans to persist objects into a database.  I was wondering if there was a way to retrieve and auto increment key back from the database after persisting the object. For instance in the code below.  I need to retrieve the id in user to send it to the setUserAssignmentTask as well as retrieve the UserAssignmentTask id.  

                em.persist(user);
                Integer primaryKey = this.setUserAssignmentTask(user.getId(),user.getFKsalesmanid());                
                String[] addresses = {"someone@somewhere.com"};
                String message = user.getFirstName() + " " + user.getLastName() + " has requested to be assigned to you \n"
                        + "Click on this link to accept this request <a href=\"http://localhost:8080/foodShow/assignUser.jsp?assignId="
                        + primaryKey.toString() + "\">http://localhost:8080/testProject/assignUser.jsp?assignId="
                        + primaryKey.toString() + "</a>";
                attendeeRegistration.SendMail sm = new attendeeRegistration.SendMail("ProjectTest",addresses,"someone@somewhere.com", message);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros