Home » Java » passing user defined table as argument to a sql server stored procedure using hibernate

passing user defined table as argument to a sql server stored procedure using hibernate

Posted by: admin October 21, 2018 Leave a comment

Questions:

I am calling a stored procedure of sql server which takes a user defined table as argument. When i make call to this it gives exception like

com.microsoft.sqlserver.jdbc.SQLServerException: Operand type clash: 
varbinary is incompatible with TripRoute.

org.hibernate.exception.SQLGrammarException: could not execute statement

TripRoute this is my user defined  table  which has following columns

Id(int,null)
RouteName(varchar(255),null)
oLat(varchar(20),null)
oLon(varchar(20),null)
...

This is my code for calling the procedure

    public ProceRoutePointsResponse callProcedureForRoutePoints(List<RouteWithDestLatLonModel> routeWithDlList) {
        ProceRoutePointsResponse proceRoutePointsResponse = null;
        SQLQuery sqlExecuteQuery = (SQLQuery) currentSession().createSQLQuery("exec [dbname].[dbo].GetTripRouteLuFinal :routeWithDlList")
                  .setParameter("routeWithDlList", routeWithDlList);             
         List<Object[]> result = sqlExecuteQuery.list();
}


This is my Pojo class for argument


public class RouteWithDestLatLonModel implements Serializable {
    private int id;
    private String routeName;
    private String originLat;
    private String originLon;
    private String destLat;
    private String destLon;
    private String hopSource;
    private String hopDest;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getRouteName() {
        return routeName;
    }
    public void setRouteName(String routeName) {
        this.routeName = routeName;
    }
    public String getOriginLat() {
        return originLat;
    }
    public void setOriginLat(String originLat) {
        this.originLat = originLat;
    }
    public String getOriginLon() {
        return originLon;
    }
    public void setOriginLon(String originLon) {
        this.originLon = originLon;
    }
    public String getDestLat() {
        return destLat;
    }
    public void setDestLat(String destLat) {
        this.destLat = destLat;
    }
    public String getDestLon() {
        return destLon;
    }
    public void setDestLon(String destLon) {
        this.destLon = destLon;
    }
    public String getHopSource() {
        return hopSource;
    }
    public void setHopSource(String hopSource) {
        this.hopSource = hopSource;
    }
    public String getHopDest() {
        return hopDest;
    }
    public void setHopDest(String hopDest) {
        this.hopDest = hopDest;
    }
    @Override
    public String toString() {
        return "RouteWithDestLatLonModel [id=" + id + ", routeName=" + routeName + ", originLat=" + originLat
                + ", originLon=" + originLon + ", destLat=" + destLat + ", destLon=" + destLon + ", hopSource="
                + hopSource + ", hopDest=" + hopDest + "]";
    }

}

Please help me to solve this.if any other information required please let me know.thanks in advance.

Answers: