title: how to get priamry key in return after inserting the row in table with liferay custom MVC portlet?
body: <p>I am developing one custom portlet with mvc in eclipse IDE.</p>
  
  <p>Following is my scenario:</p>
  
  <p>I have one table name as <code>restaurant</code> and from <code>addrestaurant.jsp</code> page I am adding the data in restaurant table.</p>
  
  <p>In my <code>addrestaurant.jsp</code> page I have following code of select control which takes multiple value to be selected:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;label&gt;Select Ad Type&lt;span class="f_req"&gt;*&lt;/span&gt;&lt;/label&gt;                                                
  &lt;select data-placeholder="- Select Ad Type -" class="chzn-select" multiple name="ad_type" value="&lt;%=restaurantOBJ.getAdtypeId()%&gt;"&gt;
      &lt;option value="1"&gt;Standby Ad&lt;/option&gt;
      &lt;option value="2"&gt;Homepage Ad&lt;/option&gt;
      &lt;option value="3"&gt;Slider Ad&lt;/option&gt;
      &lt;option value="4"&gt;Event Based Ad&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Now this <code>adtype</code> selected from <code>addrestaurant.jsp</code> will be inserted in one <code>rest_map_adtype</code> table,
  where I want to add these selected value with the reference of restaurant primary-key which is just created last.</p>
  
  <p>So how can I get the primary key of <code>restaurant</code> which is last edited</p>
  
  <p>For more explanation let me give some code snippet:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void addRestaurant(ActionRequest request, ActionResponse response) {
  
      log.info("Inside addRegistration");
      List&lt;String&gt; errors = new ArrayList&lt;String&gt;();
  
      restaurant rest = RestaurantActionUtil
              .getRestaurantFromRequest(request);     
  
      boolean restValid = RestaurantValidator
              .validateRestaurant(rest, errors);
  
      if (restValid) {
          try {
              log.info(rest);
  
              restaurant test = restaurantLocalServiceUtil
                      .addrestaurant(rest);
  
          //Above Code will add the all data which is in my addrestaurant.jsp accept just selected control values
  
              String[] adtype_ID=request.getParameterValues("ad_Type");
  
              //here am taking the select tag's multiple value in one string array
  </code></pre>
  
  <p>So after this line I need to add all the values in <code>rest_map_Adtype</code> table with the reference of restaurant primary key which is just created with the <code>addrestaurant(rest)</code> method just a line above.</p>
  
  <p>How can I make it possible?</p>
  
  <p>or how can I get the primary key in return after inserting the row in table?</p>
  
  <p>My ActionUtil.class follows</p>
  
  <pre class="lang-java prettyprint-override"><code>public restaurant addRestaurant(restaurant restParam) {
          restaurant restVar;
  
          try {
  
  
  
              restVar = restaurantPersistence.create(counterLocalService
                      .increment(restaurant.class.toString()));
          } catch (SystemException e) {
              e.printStackTrace();
              return restVar = null;
          }
  
          try {
  
  
  
              resourceLocalService.addResources(restParam.getGroupId(),restParam.getGroupId(), restParam.getUserId(),
                      restaurant.class.getName(),restParam.getPrimaryKey(), false,true,true);
          } catch (PortalException e) {
              e.printStackTrace();
              return restVar = null;
          } catch (SystemException e) {
              e.printStackTrace();
              return restVar = null;
          }
  
          restVar.setName(restParam.getName());
          restVar.setAdress(restParam.getAdress());
          restVar.setCity(restParam.getCity());
          restVar.setPin(restParam.getPin());
          restVar.setState(restParam.getState());
          restVar.setCountry(restParam.getCountry());
          restVar.setContactno(restParam.getContactno());
          restVar.setEmail(restParam.getEmail());
          restVar.setWebsite(restParam.getWebsite());
          restVar.setCuisinetype(restParam.getCuisinetype());
          restVar.setPersonalmail(restParam.getPersonalmail());
          restVar.setPersonalname(restParam.getPersonalname());
          restVar.setPersonalPhone(restParam.getPersonalPhone());
          restVar.setNoofemenuagent(restParam.getNoofemenuagent());
          restVar.setLicensekey(restParam.getLicensekey());
          restVar.setRestregId(restParam.getRestregId());
          restVar.setNoofdiningtable(restParam.getNoofdiningtable());
          restVar.setAvgnoofcustomermonthly(restParam.getAvgnoofcustomermonthly());
          restVar.setAveragroupagevisit(restParam.getAveragroupagevisit());
          restVar.setImpoflocation(restParam.getImpoflocation());
          restVar.setAvgmonthlycheckamount(restParam.getAvgmonthlycheckamount());
          restVar.setCostperthousandimpression(restParam.getCostperthousandimpression());
          restVar.setAdtypeId(restParam.getAdtypeId());
          //restVar.setNoofdiningtable(restParam.getNoofdiningtable());
          //restVar.setAvgnoofcustomermonthly(restParam.getAvgnoofcustomermonthly());
  
  
          restVar.setIsactive(restParam.getIsactive());
          restVar.setCreateddate(restParam.getCreateddate());
          restVar.setLastmodifiedby(restParam.getLastmodifiedby());
          restVar.setModifieddate(restParam.getModifieddate());
          restVar.setGroupId(restParam.getGroupId());
          restVar.setUserId(restParam.getUserId());
          restVar.setIsdeleted(restParam.getIsdeleted());
          restVar.setRestregId(restParam.getRestregId());
  
          //restVar.setOrganizationId(restParam.getOrganizationId());
  
          try {
              return restaurantPersistence.update(restVar, false);
          } catch (SystemException e) {
              e.printStackTrace();
              return restVar = null;
          }
      }
  </code></pre>
  
  <p>following is my object restaurant which returns following value after add restaurant      <code>{restId=0, name=aaaa, isactive=false, userId=10158, groupId=10180, createddate=Fri Oct 26 12:40:53 GMT 2012, lastmodifiedby=10158, modifieddate=Fri Oct 26 12:40:53 GMT 2012, restregId=12333, adress=, city=AHMEDABAD, pin=, state=, country=, contactno=, email=, website=, cuisinetype=, noofemenuagent=0, personalname=, personalPhone=, personalmail=, adtypeId=0, isdeleted=false, licensekey=12333, noofdiningtable=0, averagroupagevisit=0, impoflocation=, avgnoofcustomermonthly=0, avgmonthlycheckamount=0, costperthousandimpression=0.0}</code></p>
  
  <p>restaurantLocalServiceUtil Class</p>
  
  <pre class="lang-java prettyprint-override"><code>public static emenu.advertise.database.model.restaurant addrestaurant(
          emenu.advertise.database.model.restaurant restaurant)
          throws com.liferay.portal.kernel.exception.SystemException {
          return getService().addrestaurant(restaurant);
      }
  
      /**
      * Creates a new restaurant with the primary key. Does not add the restaurant to the database.
      *
      * @param restId the primary key for the new restaurant
      * @return the new restaurant
      */
      public static emenu.advertise.database.model.restaurant createrestaurant(
          long restId) {
          return getService().createrestaurant(restId);
      }
  </code></pre>