0

Am getting the below error

No Dialect mapping for JDBC type: 2003; nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: 2

Repo Code is as follows

    String chrPackageId = "select\n" +
         "\tcombination_hr_id as \"chRuleId\",\n" +
         "\tcombination_hr_name as \"chRuleName\", \n" +
        "\tholdingrule_list as \"selectedRules\"\n" +
         "from\n" +
         "\tcombination_holding_rule chr\n" +
         "where\n" +
         "\tpackage_id =:packageId";

@Query(value=chrPackageId,nativeQuery = true)
List<CHRfromPackageIdDTO> repoCHRFromPackageId(int packageId);

DTO object is as below

public interface CHRfromPackageIdDTO {

    int getChRuleId();
    String getChRuleName();
    Integer[] getSelectedRules();
}

We use Postgres DB, there is some issue in getting the Integer[] value actually.

The other answers in Stackoverflow are Hibernate specific. but we use spring-data-jpa.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
F0cus
  • 585
  • 3
  • 18
  • 52
  • 1
    Does this answer your question? [No Dialect mapping for JDBC type: 2003](https://stackoverflow.com/questions/21630370/no-dialect-mapping-for-jdbc-type-2003) – Jens Schauder Jul 12 '21 at 11:55
  • 1
    Spring Data JPA is build on top of JPA, which is in your case implemented by Hibernate. And Hibernate is throwing the exception. – Jens Schauder Jul 12 '21 at 11:55
  • @JensSchauder I tried the solutions from the other link you provided. but am stuck in a new issue https://stackoverflow.com/questions/68360682/no-converter-found-capable-of-converting-from-type-java-lang-integer-to-type – F0cus Jul 13 '21 at 10:48

1 Answers1

0

Entity Class



import com.vladmihalcea.hibernate.type.array.IntArrayType;
import com.vladmihalcea.hibernate.type.array.StringArrayType;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.*;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@TypeDefs({
        @TypeDef(
                name = "string-array",
                typeClass = StringArrayType.class
        ),
        @TypeDef(
                name = "int-array",
                typeClass = IntArrayType.class
        ),
        @TypeDef(name = "json", typeClass = JsonStringType.class),
        @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
@Entity
@Table(name="combination_holding_rule")
public class CombHoldingRule {

    @Id
    @Column(name="combination_hr_id")//Checked
    private Integer combHoldingRuleId;
    @Column(name="combination_hr_name")//Checked
    private String combHoldingRuleName;
    @Column(name="jurisdiction_id")//Checked
    private Integer  jurisdictionId;
    @Column(name="function_group_id")//Checked
    private Integer  functionGroupId;
    @Column(name="overall_netting_type")//Checked
    private String overallNettingType;
    @Column(name="package_id")//Checked
    private Integer  packageId;

    @Type(type = "int-array")
    @Column(
            name = "holdingrule_list",
            columnDefinition = "integer[]"
    )
    private int[] holdingRuleList;

}

In Repository

@Query(value="from CombHoldingRule where packageId=:packageId")
    List<CombHoldingRule> repoCHRFromPackageId(@Param("packageId") int packageId);

I took the result from JPAQuery into the Entity , then did the below in the Service Layer

public List<CHRfromPackageIdDTO> getCHRFromPackageIdService(int packageId) {
       
        List<CombHoldingRule> combHoldingRuleList = combinationHRrepo.
                                           repoCHRFromPackageId(packageId);
        List<CHRfromPackageIdDTO> combDTO = new ArrayList<>();
        for ( CombHoldingRule combHoldingRule : combHoldingRuleList) {            
            CHRfromPackageIdDTO temp = new CHRfromPackageIdDTO(combHoldingRule.getCombHoldingRuleId(),
                    combHoldingRule.getCombHoldingRuleName(),
                    combHoldingRule.getHoldingRuleList());
            combDTO.add(temp);
        }       
        return combDTO;
    }

Also pls check HERE

Note: This is kind of work around I believe, really not sure , how to directly take value from a native query into a custom Pojo instead of an entity class. I really appreciate if anyone post the answer for that. I would accept that as the Answer.

F0cus
  • 585
  • 3
  • 18
  • 52