<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Getting primary key from result of XXXXLocalServiceUtil.addXXX(..)</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121294243" />
  <subtitle>Getting primary key from result of XXXXLocalServiceUtil.addXXX(..)</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121294243</id>
  <updated>2026-04-03T23:05:35Z</updated>
  <dc:date>2026-04-03T23:05:35Z</dc:date>
  <entry>
    <title>RE: Getting primary key from result of XXXXLocalServiceUtil.addXXX(..)</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121295993" />
    <author>
      <name>Russell Bohl</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121295993</id>
    <updated>2021-12-13T18:50:20Z</updated>
    <published>2021-12-13T18:50:19Z</published>
    <summary type="html">&lt;p&gt;I'm not entirely certain what you're running into, but the pattern
  you're using doesn't look like the one we use in Liferay.&lt;/p&gt;
&lt;p&gt;There are useful services that are injected for you to use in your
  service impl.&lt;/p&gt;
&lt;p&gt;To generate and increment the ID use &lt;code&gt;long alertId = counterLocalService.increment();&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To create the entity, use &lt;code&gt;alertsPersistence.create(alertId);&lt;/code&gt;&lt;/p&gt;</summary>
    <dc:creator>Russell Bohl</dc:creator>
    <dc:date>2021-12-13T18:50:19Z</dc:date>
  </entry>
  <entry>
    <title>Getting primary key from result of XXXXLocalServiceUtil.addXXX(..)</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121294242" />
    <author>
      <name>Kevin Neibarger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121294242</id>
    <updated>2021-12-13T18:04:29Z</updated>
    <published>2021-12-10T23:47:21Z</published>
    <summary type="html">&lt;p&gt;So, I'm having issues with the &amp;quot;add&amp;quot; methods of
  servicebuilder methods. I have a database table that holds an alert
  record, and it's primary key &amp;quot;alert_id&amp;quot; is auto incremented,
  so everytime you insert a record it inserts with the next incremented
  value. When I build an Object to add to the Entity/Table&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Alerts a = AlertsLocalServiceUtil.&lt;i&gt;createAlerts&lt;/i&gt;(0);&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And then I do the &amp;quot;add&amp;quot; method with the returned value&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Alerts added = AlertsLocalServiceUtil.&lt;i&gt;addAlerts&lt;/i&gt;(a);&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When I print out &lt;b&gt;added.getAlertId()&lt;/b&gt; it's always 0. It should
  be the next incremented value. I need it to add a record to another table.&lt;/p&gt;
&lt;p&gt;My only solution is to query the current table for the last inserted
  record and get the alertId. That's killing performance as you can imagine.. &lt;/p&gt;
&lt;p&gt;Why doesn't &lt;b&gt;added.getAlertId() &lt;/b&gt;return the alertId inserted
  into the DB Table?? &lt;/p&gt;</summary>
    <dc:creator>Kevin Neibarger</dc:creator>
    <dc:date>2021-12-10T23:47:21Z</dc:date>
  </entry>
</feed>
