How to get id after saved object in db in JPA?
<p>I facing issue when i am getting id after saving the claimDetail object then to get the id of that saved object it is coming 0 . Actually I want get that saved object Id .But it not coming. I did not work  with JPA. I have created a Spring Boot application for scheduling .</p>

<p>Here is my ClaimDetails.java entity class:</p>

<pre><code>@Entity
@Table(name = "claimtrans")
public class ClaimTrans {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
}

    claimDetail.setActive(1);
    claimDetail.setVersion(new Long(1));
    claimDetail.setCreatedBy(new Long(1));
    claimDetail.setCreatedDate(new Date());
    claimDetailService.saveClaimDetail(claimDetail);

int temp =claimDetail.getID()
</code></pre>

<p>temp  is 0;</p>

<p>Here is my JpaRepositoryFactory.java:</p>

<pre><code>@Service
public class ClaimDetailService {

    private JpaRepositoryFactory jpaRepositoryFactory;

    @Autowired
    public ClaimDetailService(JpaRepositoryFactory jpaRepositoryFactory) {
        this.jpaRepositoryFactory = jpaRepositoryFactory;
    }

    @Transactional
    public void saveClaimDetail(ClaimDetail claimDetail) {
        JpaRepository&lt;ClaimDetail, Long&gt; mailAuditLogLongJpaRepository = jpaRepositoryFactory.getRepository(ClaimDetail.class);
        mailAuditLogLongJpaRepository.save(claimDetail);
    }

    public List&lt;ClaimDetail&gt; getAllClaimDetail() {
        JpaRepository&lt;ClaimDetail, Long&gt; mailAuditLogLongJpaRepository = jpaRepositoryFactory.getRepository(ClaimDetail.class);
        return mailAuditLogLongJpaRepository.findAll();
    }
}
</code></pre>

<p>Here is my JPA Factory.</p>

<pre><code>@Component
public class JpaRepositoryFactory {

    @PersistenceContext
    private EntityManager entityManager;

    public &lt;T&gt; T getRepository(Class clazz) {
        notNull(clazz);
        notNull(entityManager);
        T crudRepository = (T) new SimpleJpaRepository(clazz, entityManager);
        return crudRepository;
    }
}   
</code></pre>

<p>pom.xml</p>

<pre><code>&lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;1.3.5.RELEASE&lt;/version&gt;
    &lt;/parent&gt;
    &lt;properties&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;start-class&gt;org.sam.application.Application&lt;/start-class&gt;
        &lt;java.version&gt;1.6&lt;/java.version&gt;
    &lt;/properties&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;mysql&lt;/groupId&gt;
            &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
            &lt;version&gt;5.1.10&lt;/version&gt;
        &lt;/dependency&gt;
</code></pre>

<p>Anyone can help me please how to fix this issue ?</p>

<p>Thanks
Sitansu</p>