Provided id of the wrong type for class classname Expected: class java.lang.Integer, got class java.lang.String

Kunal Batra

Here is my sql table description

desc product_details;
+--------------------+-------------+------+-----+---------+-------+
| Field              | Type        | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+-------+
| action             | varchar(5)  | YES  |     | NULL    |       |
| version            | varchar(2)  | YES  |     | NULL    |       |
| productCatalogName | varchar(50) | YES  |     | NULL    |       |
| productId          | varchar(25) | NO   |     | NULL    |       |
| price              | varchar(10) | NO   |     | NULL    |       |
| Operator_Code      | varchar(7)  | YES  |     | NULL    |       |
| product_name       | varchar(70) | YES  |     | NULL    |       |
| subs_id            | int(11)     | NO   | PRI | 0       |       |
+--------------------+-------------+------+-----+---------+-------+

Every time when i call the get method

ProductDetail productDetail = (ProductDetail )session.get(ProductDetail .class, subs_id);

i am getting exception:

nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class tpay.table.ProductDetail. Expected: class java.lang.Integer, got class java.lang.String




package tpay.table;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="product_details")
public class ProductDetail {

    @Id
    @Column(name="subs_id")
     int subs_id;

    @Column(name="action")
    String action;

    @Column(name="version")
    String version;

    @Column(name="productCatalogName")
    String productCatalogName;

    @Column(name="productId")
    String productId;

    @Column(name="price")
    String price;

    @Column(name="Operator_Code")
    String Operator_Code;

    @Column(name="product_name")
    String product_name;



public String getAction() {
    return action;
}

public void setAction(String action) {
    this.action = action;
}

public String getVersion() {
    return version;
}

public void setVersion(String version) {
    this.version = version;
}

public String getProductCatalogName() {
    return productCatalogName;
}

public void setProductCatalogName(String productCatalogName) {
    this.productCatalogName = productCatalogName;
}

public String getProductId() {
    return productId;
}

public void setProductId(String productId) {
    this.productId = productId;
}

public String getPrice() {
    return price;
}

public void setPrice(String price) {
    this.price = price;
}

public String getOperator_Code() {
    return Operator_Code;
}

public void setOperator_Code(String operator_Code) {
    Operator_Code = operator_Code;
}

public String getProduct_name() {
    return product_name;
}

public void setProduct_name(String product_name) {
    this.product_name = product_name;
}

public int getSubs_id() {
    return subs_id;
}

public void setSubs_id(int subs_id) {
    this.subs_id = subs_id;
}   



}

As you can see i have already use int variable for the primary key subs_id then why its giving exception Provided id of the wrong type for class tpay.table.ProductDetail. Expected: class java.lang.Integer, got class java.lang.String

Mikko Maunu

Type of the id given to the session.get is wrong. As told by error message, String was given when Integer was expected:

Expected: class java.lang.Integer, got class java.lang.String

Such an error occurs with following code:

String subs_id = "1";
ProductDetail productDetail = (ProductDetail )
    session.get(ProductDetail .class, subs_id);

And with this code type is correct and no error occurs:

Integer subs_id = 1; //or primitive int
ProductDetail productDetail = (ProductDetail )
    session.get(ProductDetail .class, subs_id);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Java Hibernate Error: Provided id of the wrong type for class example4.heroesMap. Expected: class java.lang.Integer, got class java.lang.String

Provided id of the wrong type for class got class java.lang.Integer

InvalidTypeException: Invalid type for value 1 of CQL type text, expecting class java.lang.String but class [Ljava.lang.Object; provided

elasticsearch mapping Expected map for property [fields] on field [name] but got a class java.lang.String

Firebase.database.DatabaseException: Expected a Map while deserializing, but got a class java.lang.String

No such property: id for class: java.lang.String

Cannot cast class java.lang.Integer to class java.lang.String

Method showString([class java.lang.Integer, class java.lang.Integer, class java.lang.Boolean]) does not exist in PySpark

com.google.firebase.database.DatabaseException : Expected a Map while deserializing, but got a class java.lang.Long

Google Cloud Endpoints error Caused by: java.lang.IllegalArgumentException: expected primitive class, but got

javax.el.ELException: Cannot convert abcCache of type class java.lang.String to class java.lang.Class

Class required a bean of type 'java.lang.String' that could not be found

java.lang.NoSuchMethodException : package.ClassName.<init>() Using Class<?>

java.lang.IllegalArgumentException: Not a managed type: class

No such property: split for class: java.lang.String

java.lang.String class' value variable

Provided id of the wrong type for class when testing

Java: .class file and java.lang.Class

Cassandra-Java-driver : com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type, column is a list but class java.lang.String provided

what is the Class object (java.lang.Class)?

java.lang.IllegalArgumentException: 'json' argument must be an instance of: [class java.lang.String, class [B

Caused by: java.lang.IllegalArgumentException: Bad class: class java.lang.String

java.lang.IllegalArgumentException: Bad class: class java.lang.String

Exception in main java.lang.ClassCastException:class java.lang.String can't be cast to class

JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String

Collections.sort method is throwing class java.lang.Integer cannot be cast to class java.lang.Double error

JsonMappingException Duplicate property ... for [simple type, class java.lang.Exception]

Converting a type symbol to a java.lang.Class instance

nested exception is java.lang.IllegalArgumentException: Not a managed type: class