Note that there are some explanatory texts on larger screens.

plurals
  1. POfindBy... Method returning null value in spring data jpa
    primarykey
    data
    text
    <p>I'm pretty new to spring data and trying to analyze piece of code. Here it goes.</p> <p><b>BaseRepository.java</b></p> <pre><code>import java.io.Serializable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.NoRepositoryBean; /** * Base Repository is a generic repository * * */ @NoRepositoryBean public interface BaseRepository&lt;T, ID extends Serializable&gt; extends JpaRepository&lt;T, ID&gt;, JpaSpecificationExecutor&lt;T&gt; {} </code></pre> <p><b>SectionChainView.java</b></p> <pre><code>@Entity @Table(name = "SECTION_CHAIN_VIEW", schema = "RPM") public class SectionChainView implements BaseEntity { public SectionChainView() {} public SectionChainView(SectionChainViewId id) { this.id = id; } public SectionChainViewId getId() { return id; } public void setId(SectionChainViewId id) { this.id = id; } @EmbeddedId @AttributeOverrides( { @AttributeOverride(name="contractId", column=@Column(name="CONTRACT_ID",nullable=false, length=5) ), @AttributeOverride(name="sectionId", column=@Column(name="SECTION_ID", nullable=false, length=1) ), @AttributeOverride(name="chainId", column=@Column(name="CHAIN_ID", nullable=false, length=4) ), @AttributeOverride(name="name", column=@Column(name="NAME") ) } ) private SectionChainViewId id; } </code></pre> <p><b>SectionChainViewId.java</b></p> <pre><code>@Embeddable public class SectionChainViewId implements BaseEntity { private static final long serialVersionUID = 1L; public SectionChainViewId() {} public String getContractId() { return contractId; } public void setContractId(String contractId) { this.contractId = contractId; } public String getSectionId() { return sectionId; } public void setSectionId(String sectionId) { this.sectionId = sectionId; } public String getChainId() { return chainId; } public void setChainId(String chainId) { this.chainId = chainId; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Column(name="CONTRACT_ID", nullable=false, length=5) private String contractId; @Column(name="SECTION_ID", nullable=false, length=1) private String sectionId; @Column(name="CHAIN_ID", nullable=false, length=4) private String chainId; @Column(name = "NAME") private String name; public boolean equals(Object other) { if ( (this == other ) ) return true; if ( (other == null ) ) return false; if ( !(other instanceof SectionChainViewId) ) return false; SectionChainViewId castOther = ( SectionChainViewId ) other; return ( (this.getContractId()==castOther.getContractId()) || ( this.getContractId()!=null &amp;&amp; castOther.getContractId()!=null &amp;&amp; this.getContractId().equals(castOther.getContractId()) ) ) &amp;&amp; ( (this.getSectionId()==castOther.getSectionId()) || ( this.getSectionId()!=null &amp;&amp; castOther.getSectionId()!=null &amp;&amp; this.getSectionId().equals(castOther.getSectionId()) ) &amp;&amp; ( (this.getChainId()==castOther.getChainId()) || ( this.getChainId()!=null &amp;&amp; castOther.getChainId()!=null &amp;&amp; this.getChainId().equals(castOther.getChainId()))) &amp;&amp; ( (this.getName()==castOther.getName()) || ( this.getName()!=null &amp;&amp; castOther.getName()!=null &amp;&amp; this.getName().equals(castOther.getName())))) ; } public int hashCode() { int result = 17; result = 37 * result + ( getContractId() == null ? 0 : this.getContractId().hashCode() ); result = 37 * result + ( getSectionId() == null ? 0 : this.getSectionId().hashCode() ); result = 37 * result + ( getChainId() == null ? 0 : this.getChainId().hashCode() ); result = 37 * result + ( getName() == null ? 0 : this.getName().hashCode() ); return result; } } </code></pre> <p><b>SectionChainViewRepository.java</b></p> <pre><code>public interface SectionChainViewRepository extends BaseRepository&lt;SectionChainView, SectionChainViewId&gt; { @Query("select s from SectionChainView s where s.id.contractId = ?1 and s.id.sectionId = ?2") public List&lt;SectionChainView&gt; findByContractIdAndSectionId(String contractId, String sectionId); } </code></pre> <p>And the SECTION_CHAIN_VIEW is a view from oracle database while looks like this.</p> <pre><code>|-----------------------------------------------------| |CONTRACT_ID SECTION_ID CHAIN_ID NAME | |-----------------------------------------------------| | 001 A ABC Andy | | 002 B XYZ Mike | | 003 C PQR (null)| ------------------------------------------------------- </code></pre> <p>And when there is no value in NAME column or null.Here in my case, the contract 003 where my NAME column has null value. The findByContractIdAndSectionId method of SectionChainViewRepository is returning List with only 2 SectionChain objects instead of 3 objects. I noticed that when there is NULL value then its not returning SectionChain Object. Any help by solving getting 3 SectionChain objects instead of 2 is truely appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload