Discussions

EJB programming & troubleshooting: EJB AutoGenerated ID and Persistance Question

  1. EJB AutoGenerated ID and Persistance Question (2 messages)

    Hello! Just started using EJB 3.0 so bare with me please.. The question is regarding an entity with an auto generated ID public class Appointment implements Serializable { ... private int appid; ... @Id @GeneratedValue @Column(name="APP_ID") public int getAppId( ) { return appid; } public void setAppId(int pk) { appid = pk; } ... } When I take an instance of this POJO entity and persist it entitymanager.persist(appointment); I would like to know what appId it was given since I need this value for the next step in my process. I cannot use entitymanager.find(..) since I don't know the PK and performing a query on all the other columns cant be done since they are not unique. There must be a better way.. Does anyone know? Thanks a lot! Scott
  2. Re:Resolved[ Go to top ]

    Problem resolved.. Thanks anyways
  3. Hi, Suppose, 1 .Module in the entity-is having the getter/setter method 2. After Module entity is persisted, then you can get the Primary key value entitymanager.persist(module); By debug mode,check primary key value present/ or not in the module entity attributes after calling the above method. I think, this will solve your problem.