Fourni id de type incorrect pour la classe nom de la classe Attendue: la classe java.lang.Entier, a obtenu de la classe java.lang.Chaîne
Voici ma table sql 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 | |
+--------------------+-------------+------+-----+---------+-------+
À chaque fois lorsque j'appelle la méthode get
ProductDetail productDetail = (ProductDetail )session.get(ProductDetail .class, subs_id);
je suis arriver 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;
}
}
Comme vous pouvez le voir j'ai déjà utiliser la variable int pour la clé primaire subs_id
alors pourquoi donner son exception
Fourni id de type incorrect pour la classe tpay.table.ProductDetail. Attendu: la classe java.lang.Entier, a obtenu de la classe java.lang.Chaîne
Vous devez vous connecter pour publier un commentaire.
Type de l'id donné à la session.obtenir est faux. Comme indiqué par le message d'erreur, la Chaîne a été donné lors de l'Entier a été prévu:
Une telle erreur se produit avec le code suivant:
Et avec ce type de code est correct et aucune erreur ne se produit: