facebook

Approach to managing primary key and autoincement

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #311211 Reply

    Greg Soulsby
    Member

    Hi,

    Am working on my first bespoke function post scaffolding. When I go to save a record I get

    “ids for this class must be manually assigned before calling save()”

    This, and an old forum comment, implies that autoincremente is not being used? If so, I am currious to know why but more importantly would like to understand if my approach right, the options and the pro and cons.

    Code is:

    @RequestMapping(“/runPanProc.action”)
    public ModelAndView runPanProc(@RequestParam Integer procId) {
    ModelAndView mav = new ModelAndView();
    PanProcedures proc = panProceduresDAO.findPanProceduresByPrimaryKey(procId);
    PanProcRuns r = new PanProcRuns();
    String m = proc.getProcedureName();
    r.setProcRunMemo(proc.getProcedureName().concat(“: Has memo: “).concat(m));
    r.setProcRunRunType(“development”);
    r.setProcRunProcedureId(procId);
    *** fail hereon this next line ****
    r = panProcRunsDAO.store(r);
    panProcRunsDAO.flush();
    mav.addObject(“panprocruns”, r);
    mav.setViewName(“panprocruns/viewPanProcRuns.jsp”);
    return mav;
    }

    Regards

    #311217 Reply

    davemeurer
    Member

    Hello,

    For Primary Keys that are auto-increment, take a look into adding additional identifier JPA/Hibernate annotations in the Domain Object. Specifically the @GeneratedValue annotation. The complex part is that the generation strategy and annotational values for autonumbers can be different for each database. This is something that is in our feature request queue to support in the future, and I appreciate you mentioning it (since it helps us prioritize)

    Here are a couple sites that help explain this annotation, but I would also search for GeneratedValue and the database you are using to get the specific syntax for your db.

    Hibernate Docs on Identifiers: http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-identifier
    Primary Key Eclipse Wiki: http://wiki.eclipse.org/EclipseLink/Examples/JPA/PrimaryKey

    HTH,
    Dave

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Approach to managing primary key and autoincement

You must be logged in to post in the forum log in