Kundera ClassCastException with MongoDB - java

I'm using Kundera to do the persistence in MongoDB. I can persist some documents in my collection, but everytime that I try to find a specific document by id, I get this error
java.lang.ClassCastException: java.lang.String cannot be cast to com.mongodb.BasicDBList
com.impetus.kundera.persistence.AbstractEntityReader.findById(AbstractEntityReader.java:95)
com.impetus.client.mongodb.MongoEntityReader.findById(MongoEntityReader.java:72)
com.impetus.kundera.lifecycle.states.ManagedState.handleFind(ManagedState.java:com.impetus.kundera.graph.Node.find(Node.java:500)
com.impetus.kundera.persistence.PersistenceDelegator.find(PersistenceDelegator.java:225)
com.impetus.kundera.persistence.PersistenceDelegator.findById(PersistenceDelegator.java:174)
com.impetus.kundera.persistence.EntityManagerImpl.find(EntityManagerImpl.java:263)
My class definition is
package data.additional;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.google.common.collect.Lists;
#Entity
#Table(name = "reference", schema = "RcordsDB#pl_records")
public class Reference {
#Id
#Column(name="idReference")
private String idReference;
#Column(name="profile_id")
private String profile_id;
#Column(name="group_id")
private String group_id;
#Column(name="created")
private Date created;
#Column(name="last_modified")
private Date last_modified;
#Column(name="identifiers")
private List<String> identifiers = Lists.newArrayList();
#Column(name="abstractText")
private String abstractText;
#Column(name="tags")
private String tags;
#Column(name="type")
private String type;
#Column(name="source")
private String source;
#Column(name="title")
private String title;
#Column(name="title")
private List<String> authors = Lists.newArrayList();
#Column(name="year")
private Date year;
#Column(name="volume")
private String volume;
#Column(name="issue")
private String issue;
#Column(name="pages")
private String pages;
#Column(name="series")
private String series;
#Column(name="chapter")
private String chapter;
#Column(name="websites")
private String websites;
#Column(name="accesed")
private String accesed;
#Column(name="publisher")
private String publisher;
#Column(name="city")
private String city;
#Column(name="edition")
private String edition;
#Column(name="institution")
private String institution;
#Column(name="editors")
private List<String> editors = Lists.newArrayList();
#Column(name="keywords")
private List<String> keywords = Lists.newArrayList();
#Column(name="doi")
private String doi;
#Column(name="isbn")
private String isbn;
#Column(name="issn")
private String issn;
public String getIdReference() {
return idReference;
}
public void setIdReference(String idReference) {
this.idReference = idReference;
}
public String getProfile_id() {
return profile_id;
}
public void setProfile_id(String profile_id) {
this.profile_id = profile_id;
}
public String getGroup_id() {
return group_id;
}
public void setGroup_id(String group_id) {
this.group_id = group_id;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getLast_modified() {
return last_modified;
}
public void setLast_modified(Date last_modified) {
this.last_modified = last_modified;
}
public List<String> getIdentifiers() {
return identifiers;
}
public void setIdentifiers(List<String> identifiers) {
this.identifiers = identifiers;
}
public String getAbstractText() {
return abstractText;
}
public void setAbstractText(String abstractText) {
this.abstractText = abstractText;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<String> getAuthors() {
return authors;
}
public void setAuthors(List<String> authors) {
this.authors = authors;
}
public Date getYear() {
return year;
}
public void setYear(Date year) {
this.year = year;
}
public String getVolume() {
return volume;
}
public void setVolume(String volume) {
this.volume = volume;
}
public String getIssue() {
return issue;
}
public void setIssue(String issue) {
this.issue = issue;
}
public String getPages() {
return pages;
}
public void setPages(String pages) {
this.pages = pages;
}
public String getSeries() {
return series;
}
public void setSeries(String series) {
this.series = series;
}
public String getChapter() {
return chapter;
}
public void setChapter(String chapter) {
this.chapter = chapter;
}
public String getWebsites() {
return websites;
}
public void setWebsites(String websites) {
this.websites = websites;
}
public String getAccesed() {
return accesed;
}
public void setAccesed(String accesed) {
this.accesed = accesed;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getEdition() {
return edition;
}
public void setEdition(String edition) {
this.edition = edition;
}
public String getInstitution() {
return institution;
}
public void setInstitution(String institution) {
this.institution = institution;
}
public List<String> getEditors() {
return editors;
}
public void setEditors(List<String> editors) {
this.editors = editors;
}
public List<String> getKeywords() {
return keywords;
}
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getIssn() {
return issn;
}
public void setIssn(String issn) {
this.issn = issn;
}
}

There is no error from Kundera side. The error is in the Entity class. You have given same Column Name to these two fields.
#Column(name="title")
private List<String> authors = Lists.newArrayList();
#Column(name="title")
private String title;
Update that name & your code will be working fine.

Related

org.springframework.orm.jpa.JpaSystemException: Error accessing field by reflection for persistent property

I am using Spring Boot (v 2.4.0) with Hibernate 5.4.24 and, when trying to get some information from my database, I keep getting this error message:
org.springframework.orm.jpa.JpaSystemException: Error accessing field [private int es.uc3m.orders.model.Shoppingcart.usID] by reflection for persistent property [es.uc3m.orders.model.Shoppingcart#usID] : 1; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private int es.uc3m.orders.model.Shoppingcart.usID] by reflection for persistent property [es.uc3m.orders.model.Shoppingcart#usID] : 1
It is kind of weird for me, because it only happens when I try to access the table Shoppingcart, since I can get informatin from the rest of the tables.
I also used the exact same entities with another project but, insetad of using Spring Boot, persistence was made with EntityManagers and it worked perfectly fine.
These are my entities:
Shoppingcart
#Entity
#NamedQuery(name="Shoppingcart.findAll", query="SELECT s FROM Shoppingcart s")
public class Shoppingcart implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int scID;
private int usID;
//bi-directional many-to-many association to Product
#ManyToMany
#JoinTable(
name="sc_has_product"
, joinColumns={
#JoinColumn(name="scID")
}
, inverseJoinColumns={
#JoinColumn(name="productID")
}
)
private List<Product> products;
//bi-directional one-to-one association to User
#OneToOne(mappedBy="shoppingcart")
private User user;
public Shoppingcart() {
}
public int getScID() {
return this.scID;
}
public void setScID(int scID) {
this.scID = scID;
}
public int getusID() {
return this.usID;
}
public void setusID(int usID) {
this.usID = usID;
}
public List<Product> getProducts() {
return this.products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
public boolean isNull() {
return getProducts().isEmpty();
}
User
#Entity
#Table(name="users")
#NamedQuery(name="User.findAll", query="SELECT u FROM User u")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String address;
#Column(name="card_n")
private Long cardN;
private String city;
private String country;
private int cvv;
private String email;
private String exp;
private String name;
private String pass;
private String surname1;
private String surname2;
private String typeOfUser;
#Column(name="zip_code")
private int zipCode;
//bi-directional many-to-one association to Order
#OneToMany(mappedBy="user")
private List<Orders> orders;
//bi-directional many-to-one association to Product
#OneToMany(mappedBy="user")
private List<Product> products;
//bi-directional one-to-one association to Shoppingcart
#OneToOne(cascade=CascadeType.REMOVE)
#JoinColumn(name="ID", referencedColumnName="usID", insertable=false, updatable=false)
private Shoppingcart shoppingcart;
public User() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public Long getCardN() {
return this.cardN;
}
public void setCardN(Long cardN) {
this.cardN = cardN;
}
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
public int getCvv() {
return this.cvv;
}
public void setCvv(int cvv) {
this.cvv = cvv;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getExp() {
return this.exp;
}
public void setExp(String exp) {
this.exp = exp;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return this.pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getSurname1() {
return this.surname1;
}
public void setSurname1(String surname1) {
this.surname1 = surname1;
}
public String getSurname2() {
return this.surname2;
}
public void setSurname2(String surname2) {
this.surname2 = surname2;
}
public int getZipCode() {
return this.zipCode;
}
public void setZipCode(int zipCode) {
this.zipCode = zipCode;
}
public List<Orders> getOrders() {
return this.orders;
}
public void setOrders(List<Orders> orders) {
this.orders = orders;
}
public Orders addOrder(Orders order) {
getOrders().add(order);
order.setUser(this);
return order;
}
public Orders removeOrder(Orders order) {
getOrders().remove(order);
order.setUser(null);
return order;
}
public List<Product> getProducts() {
return this.products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public Product addProduct(Product product) {
getProducts().add(product);
product.setUser(this);
return product;
}
public Product removeProduct(Product product) {
getProducts().remove(product);
product.setUser(null);
return product;
}
public Shoppingcart getShoppingcart() {
return this.shoppingcart;
}
public void setShoppingcart(Shoppingcart shoppingcart) {
this.shoppingcart = shoppingcart;
}
public String getTypeOfUser() {
return typeOfUser;
}
public void setTypeOfUser(String typeOfUser) {
this.typeOfUser = typeOfUser;
}
}
This is the ShoppingcartDAO class:
public interface ShoppingCartDAO extends CrudRepository<Shoppingcart, Integer> {
#Query("SELECT s FROM Shoppingcart s JOIN User u ON u.id = s.usID AND u.id LIKE :id")
Shoppingcart findByUser(#Param("id") int id);
#Query("SELECT s FROM Shoppingcart s")
List<Shoppingcart> findAllShoppingCart();
}
And, finally, this is my ShoppingcartController class:
#RestController
#CrossOrigin
#EnableAutoConfiguration
public class ShoppingCartController {
#Autowired
ShoppingCartDAO scDAO;
#RequestMapping(value = "sc", method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<?> assignShoppingCart(#RequestBody(required = true) Shoppingcart sc) {
try {
scDAO.save(sc);
return new ResponseEntity<Void>(HttpStatus.CREATED);
} catch(Exception e) {
return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
}
}
#RequestMapping(value = "sc", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<?> getEveryShoppingCart() {
try {
List<Shoppingcart> sc = scDAO.findAllShoppingCart();
return new ResponseEntity<List<Shoppingcart>>(sc, (sc != null) ? HttpStatus.OK : HttpStatus.NOT_FOUND);
} catch(Exception e) {
System.out.println(e);
return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
}
}
}
I am really going nuts as I canĀ“t figure out what is going on with my code, so thank you in advance if you help me.
I finally fixed it. For those of you who are wondering how, I deleted the relationships between tables that I had, ending with:
Shoppingcart:
#Entity
public class Shoppingcart implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int scID;
#Column(name = "usID")
private Integer userID;
public Shoppingcart() {
}
public int getScID() {
return this.scID;
}
public void setScID(int scID) {
this.scID = scID;
}
public Integer getUserID() {
return userID;
}
public void setUserID(Integer userID) {
this.userID = userID;
}
Product:
#Entity
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int productID;
private String category;
private String color;
private String description;
private String estadoProducto;
private String fecha;
private int orderID;
private String photo;
private double price;
private int seller;
private String sexo;
private String state = "Disponible";
private String talla;
private String title;
public Product() {
}
public int getProductID() {
return this.productID;
}
public void setProductID(int productID) {
this.productID = productID;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getColor() {
return this.color;
}
public void setColor(String color) {
this.color = color;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public String getEstadoProducto() {
return this.estadoProducto;
}
public void setEstadoProducto(String estadoProducto) {
this.estadoProducto = estadoProducto;
}
public String getFecha() {
return this.fecha;
}
public void setFecha(String fecha) {
this.fecha = fecha;
}
public String getPhoto() {
return this.photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public double getPrice() {
return this.price;
}
public void setPrice(double price) {
this.price = price;
}
public String getSexo() {
return this.sexo;
}
public void setSexo(String sexo) {
this.sexo = sexo;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public String getTalla() {
return this.talla;
}
public void setTalla(String talla) {
this.talla = talla;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public int getOrderID() {
return orderID;
}
public void setOrderID(int orderID) {
this.orderID = orderID;
}
public int getSeller() {
return seller;
}
public void setSeller(int seller) {
this.seller = seller;
}
With this, everything worked fine, but don't ask me why, because I don't know it.
Your Getters/Setters are wrongly implemented.
Like :
Actual :
public int getusID() {
return this.usID;
}
Expected :
public int getUsID() {
return this.usID;
}
Same with setter

Why i'm getting expected begin_array but was String

This is my json data
{
"Success": true,
"Message": "User Not Found",
"Customer_Data": "",
"Customer_Device": "",
"Customer_Event": "",
"All_Event": [
{
"event_id": 6,
"event_name": "Test Event - 1",
"start_date": "01/06/2019",
"end_date": "01/06/2019",
"address_1": "Mumbai",
"address_2": "Mumbai",
"location_link": "https://goo.gl/maps/vTia6DQxwmiA5kvz6",
"pincode": 400060,
"state_id": 10,
"city_id": 355,
"sechudel": "Test",
"itinerary": "Test",
"edate": "2019-05-09T17:00:05.95592",
"eventimg": "http://zaidicorp.in/login/ProcessImage/636935218388448729.png"
}
],
"Status": 1,
"Currentdate": "5/16/2019 11:40:54 AM"
}
this is my pojo file
package mytraining.com.mytraining.Pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
public class OtpCheck implements Serializable {
#SerializedName("Success")
#Expose
private Boolean success;
#SerializedName("Message")
#Expose
private String message;
#SerializedName("Customer_Data")
#Expose
private List<CustomerData> customerData;
#SerializedName("Customer_Device")
#Expose
private List<CustomerDevice> customerDevice;
#SerializedName("Customer_Event")
#Expose
private List<CustomerEvent> customerEvent;
#SerializedName("Event")
#Expose
private List<EventDetail> eventDetails;
#SerializedName("Status")
#Expose
private Integer status;
#SerializedName("Currentdate")
#Expose
private String currentdate;
public List<EventDetail> getEventDetails() {
return eventDetails;
}
public void setEventDetails(List<EventDetail> eventDetails) {
this.eventDetails = eventDetails;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<CustomerData> getCustomerData() {
return customerData;
}
public void setCustomerData(List<CustomerData> customerData) {
this.customerData = customerData;
}
public List<CustomerDevice> getCustomerDevice() {
return customerDevice;
}
public void setCustomerDevice(List<CustomerDevice> customerDevice) {
this.customerDevice = customerDevice;
}
public List<CustomerEvent> getCustomerEvent() {
return customerEvent;
}
public void setCustomerEvent(List<CustomerEvent> customerEvent) {
this.customerEvent = customerEvent;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getCurrentdate() {
return currentdate;
}
public void setCurrentdate(String currentdate) {
this.currentdate = currentdate;
}
/**
* Inner Class For Customer Data
*/
public static class CustomerData implements Serializable {
#SerializedName("cust_id")
#Expose
private Integer custId;
#SerializedName("cust_email")
#Expose
private String custEmail;
#SerializedName("customername")
#Expose
private String customername;
#SerializedName("personalcontact")
#Expose
private String personalcontact;
public Integer getCustId() {
return custId;
}
public void setCustId(Integer custId) {
this.custId = custId;
}
public String getCustEmail() {
return custEmail;
}
public void setCustEmail(String custEmail) {
this.custEmail = custEmail;
}
public String getCustomername() {
return customername;
}
public void setCustomername(String customername) {
this.customername = customername;
}
public String getPersonalcontact() {
return personalcontact;
}
public void setPersonalcontact(String personalcontact) {
this.personalcontact = personalcontact;
}
}
/**
* Inner Class For Customer Device
*/
public static class CustomerDevice implements Serializable {
#SerializedName("cust_id")
#Expose
private Integer custId;
#SerializedName("Cust_device")
#Expose
private String custDevice;
#SerializedName("bg_device_Brand")
#Expose
private String bgDeviceBrand;
#SerializedName("bg_device_model")
#Expose
private String bgDeviceModel;
#SerializedName("android_ver")
#Expose
private String androidVer;
#SerializedName("device_mac")
#Expose
private String deviceMac;
#SerializedName("opt")
#Expose
private Object opt;
public Integer getCustId() {
return custId;
}
public void setCustId(Integer custId) {
this.custId = custId;
}
public String getCustDevice() {
return custDevice;
}
public void setCustDevice(String custDevice) {
this.custDevice = custDevice;
}
public String getBgDeviceBrand() {
return bgDeviceBrand;
}
public void setBgDeviceBrand(String bgDeviceBrand) {
this.bgDeviceBrand = bgDeviceBrand;
}
public String getBgDeviceModel() {
return bgDeviceModel;
}
public void setBgDeviceModel(String bgDeviceModel) {
this.bgDeviceModel = bgDeviceModel;
}
public String getAndroidVer() {
return androidVer;
}
public void setAndroidVer(String androidVer) {
this.androidVer = androidVer;
}
public String getDeviceMac() {
return deviceMac;
}
public void setDeviceMac(String deviceMac) {
this.deviceMac = deviceMac;
}
public Object getOpt() {
return opt;
}
public void setOpt(Object opt) {
this.opt = opt;
}
}
/**
* Inner Class For Customer Event
*/
public static class CustomerEvent implements Serializable {
#SerializedName("ticket_no")
#Expose
private String ticketNo;
#SerializedName("seat_no")
#Expose
private String seatNo;
#SerializedName("event_name")
#Expose
private String eventName;
#SerializedName("start_date")
#Expose
private String startDate;
#SerializedName("end_date")
#Expose
private String endDate;
#SerializedName("location_link")
#Expose
private String locationLink;
#SerializedName("edate")
#Expose
private String edate;
public String getTicketNo() {
return ticketNo;
}
public void setTicketNo(String ticketNo) {
this.ticketNo = ticketNo;
}
public String getSeatNo() {
return seatNo;
}
public void setSeatNo(String seatNo) {
this.seatNo = seatNo;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public String getLocationLink() {
return locationLink;
}
public void setLocationLink(String locationLink) {
this.locationLink = locationLink;
}
public String getEdate() {
return edate;
}
public void setEdate(String edate) {
this.edate = edate;
}
}
/**
* Inner Class For Event Detail
*/
public static class EventDetail implements Serializable {
#SerializedName("event_id")
#Expose
private Integer eventId;
#SerializedName("event_name")
#Expose
private String eventName;
#SerializedName("start_date")
#Expose
private String startDate;
#SerializedName("end_date")
#Expose
private String endDate;
#SerializedName("address_1")
#Expose
private String address1;
#SerializedName("address_2")
#Expose
private String address2;
#SerializedName("location_link")
#Expose
private String locationLink;
#SerializedName("pincode")
#Expose
private Integer pincode;
#SerializedName("state_id")
#Expose
private Integer stateId;
#SerializedName("city_id")
#Expose
private Integer cityId;
#SerializedName("sechudel")
#Expose
private String sechudel;
#SerializedName("itinerary")
#Expose
private String itinerary;
#SerializedName("edate")
#Expose
private String edate;
#SerializedName("eventimg")
#Expose
private String eventimg;
public Integer getEventId() {
return eventId;
}
public void setEventId(Integer eventId) {
this.eventId = eventId;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getLocationLink() {
return locationLink;
}
public void setLocationLink(String locationLink) {
this.locationLink = locationLink;
}
public Integer getPincode() {
return pincode;
}
public void setPincode(Integer pincode) {
this.pincode = pincode;
}
public Integer getStateId() {
return stateId;
}
public void setStateId(Integer stateId) {
this.stateId = stateId;
}
public Integer getCityId() {
return cityId;
}
public void setCityId(Integer cityId) {
this.cityId = cityId;
}
public String getSechudel() {
return sechudel;
}
public void setSechudel(String sechudel) {
this.sechudel = sechudel;
}
public String getItinerary() {
return itinerary;
}
public void setItinerary(String itinerary) {
this.itinerary = itinerary;
}
public String getEdate() {
return edate;
}
public void setEdate(String edate) {
this.edate = edate;
}
public String getEventimg() {
return eventimg;
}
public void setEventimg(String eventimg) {
this.eventimg = eventimg;
}
}
}
this my is java calling class
private void eventDetial(Map<String, String> map) {
Call<OtpCheck> call = apiInterface.eventShow(map);
call.enqueue(new Callback<OtpCheck>() {
#Override
public void onResponse(Call<OtpCheck> call, Response<OtpCheck> response) {
List<OtpCheck.EventDetail> data = response.body().getEventDetails();
for (int i = 0; i < 1; i++) {
image = data.get(i).getEventimg();
Log.i("Data", "data");
Glide.with(getActivity()).load(image).into(imageView);
}
}
#Override
public void onFailure(Call<OtpCheck> call, Throwable t) {
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
I tried multiple ways from StackOverflow but still not getting error
expected begin_array but was String
Firstly got Error from below field, this 3 field is String but you set ArrayList. But it will be String. Like below.
"Customer_Data": "",
"Customer_Device": "",
"Customer_Event": "",
#SerializedName("Customer_Data")
#Expose
private String customerData;
#SerializedName("Customer_Device")
#Expose
private String customerDevice;
#SerializedName("Customer_Event")
#Expose
private String customerEvent;
Also, Have no any event field. so need change from
#SerializedName("Event")
#Expose
private List<EventDetail> eventDetails;
To
#SerializedName("All_Event")
#Expose
private List<EventDetail> eventDetails;
Your problem is in your #SerializedName:
#SerializedName("Event")
#Expose
private List<EventDetail> eventDetails;
The tag SerializedName must have the name of the element of the json. Then you must changue it for:
#SerializedName("All_Event")
#Expose
private List<EventDetail> eventDetails;

null response usin Retrofit Library in android

Here is my JSONArray Response from Web service:
And Class Java :
public class Product {
private int id,price,discount;
private String name,image,description,discount_type,discount_exp;
#SerializedName("products")
private List<Product> products;
public Product()
{
}
}
response is null
Your POJO class is wrong
Try this
public class Products_Main
{
#SerializedName("current_page")
int current_page;
#SerializedName("data")
private List<Product> products;
public int getCurrent_page() {
return current_page;
}
public void setCurrent_page(int current_page) {
this.current_page = current_page;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
}
and
class Product {
#SerializedName("id")
private int id;
#SerializedName("price")
int price;
#SerializedName("discount")
int discount;
#SerializedName("name")
private String name;
#SerializedName("image")
private String image;
#SerializedName("description")
private String description;
#SerializedName("discount_type")
private String discount_type;
#SerializedName("discount_exp")
private String discount_exp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDiscount_type() {
return discount_type;
}
public void setDiscount_type(String discount_type) {
this.discount_type = discount_type;
}
public String getDiscount_exp() {
return discount_exp;
}
public void setDiscount_exp(String discount_exp) {
this.discount_exp = discount_exp;
}
}
Any null data happens when the parsing failed.
This is the Java for the response you've shown
public class ProductResponse {
ProductPage products;
}
public class ProductPage {
int current_page;
#SerializedName("data")
private List<Product> products;
}
public class Product {
private int id,price,discount;
private String name,image,description,discount_type,discount_exp;
public Product() { }
}
You have to change like it will work
public class ProductModel {
private int current_page;
private ArrayList<DataModel> data = new ArrayList<>();
public int getCurrent_page() {
return current_page;
}
public void setCurrent_page(int current_page) {
this.current_page = current_page;
}
public ArrayList<DataModel> getData() {
return data;
}
public void setData(ArrayList<DataModel> data) {
this.data = data;
}
private class DataModel{
private int id,price,discount,shop_id,vote_id,vedeo_id,status;
private String name,image,description,discount_type,discount_exp,created_at,updated_at;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
public int getShop_id() {
return shop_id;
}
public void setShop_id(int shop_id) {
this.shop_id = shop_id;
}
public int getVote_id() {
return vote_id;
}
public void setVote_id(int vote_id) {
this.vote_id = vote_id;
}
public int getVedeo_id() {
return vedeo_id;
}
public void setVedeo_id(int vedeo_id) {
this.vedeo_id = vedeo_id;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDiscount_type() {
return discount_type;
}
public void setDiscount_type(String discount_type) {
this.discount_type = discount_type;
}
public String getDiscount_exp() {
return discount_exp;
}
public void setDiscount_exp(String discount_exp) {
this.discount_exp = discount_exp;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
public String getUpdated_at() {
return updated_at;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
}
}
The issue is that the products are contained within the data field of the JSON response. Retrofit doesn't know this so it can't deserialize the response into a Product array.
You should use it like that
=>Main API Model Class
public class APIResult {
#SerializedName("products")
private ProductModelClass products;
public ProductModelClass getProducts() {
return products;
}
public void setProducts(ProductModelClass products) {
this.products = products;
}
}
=>For data and current page model class
public class ProductModelClass {
#SerializedName("current_page")
private int current_page;
#SerializedName("data")
private ArrayList<ProductDataModel> data;
public int getCurrent_page() {
return current_page;
}
public void setCurrent_page(int current_page) {
this.current_page = current_page;
}
public ArrayList<ProductDataModel> getData() {
return data;
}
public void setData(ArrayList<ProductDataModel> data) {
this.data = data;
}
}
=>For Details of products Data
public class ProductDataModel {
#SerializedName("id")
private int id;
#SerializedName("name")
private String name;
#SerializedName("image")
private String image;
#SerializedName("description")
private String description;
#SerializedName("price")
private int price;
#SerializedName("discount")
private int discount;
#SerializedName("shop_id")
private int shop_id;
#SerializedName("discount_type")
private String discount_type;
#SerializedName("discount_exp")
private String discount_exp;
#SerializedName("discount_limit")
private String discount_limit;
#SerializedName("vote_id")
private String vote_id;
#SerializedName("video_id")
private String video_id;
#SerializedName("status")
private String status;
#SerializedName("created_at")
private String created_at;
#SerializedName("updated_at")
private String updated_at;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
public int getShop_id() {
return shop_id;
}
public void setShop_id(int shop_id) {
this.shop_id = shop_id;
}
public String getDiscount_type() {
return discount_type;
}
public void setDiscount_type(String discount_type) {
this.discount_type = discount_type;
}
public String getDiscount_exp() {
return discount_exp;
}
public void setDiscount_exp(String discount_exp) {
this.discount_exp = discount_exp;
}
public String getDiscount_limit() {
return discount_limit;
}
public void setDiscount_limit(String discount_limit) {
this.discount_limit = discount_limit;
}
public String getVote_id() {
return vote_id;
}
public void setVote_id(String vote_id) {
this.vote_id = vote_id;
}
public String getVideo_id() {
return video_id;
}
public void setVideo_id(String video_id) {
this.video_id = video_id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
public String getUpdated_at() {
return updated_at;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
}

org.hibernate.QueryException: could not resolve property with where clause

I am trying to get customers data in database based on condition where status of each customer is "Actve" this is the default value at the time of insertion but I am setting it deactivated in some query ultimately I want only those who have status "Active"
I did this
#Override
public List<Customer> listCustomers() {
return this.sessionFactory.getCurrentSession().createQuery("from customer).list();
}
But I am getting all active and deactivated customer
Then I did this
#Override
public List<Customer> listCustomers() {
return this.sessionFactory.getCurrentSession().createQuery("from com.mphasis.bharathbank.bean.customer where status="+"'Active'").list();
}
Here I am getting Exception
SEVERE: Servlet.service() for servlet [dispatcher] in context with
path [/BharathBank] threw exception [Request processing failed; nested
exception is org.hibernate.QueryException: could not resolve property:
status of: com.mphasis.bharathbank.bean.Customer [from
com.mphasis.bharathbank.bean.Customer as c where c.status=Active]]
with root cause org.hibernate.QueryException: could not resolve
property: status of: com.mphasis.bharathbank.bean.Customer [from
com.mphasis.bharathbank.bean.Customer as c where c.status=Active]
Model Customer Class
#Entity(name="customer")
#Table(name="customer")
public class Customer implements Serializable{
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy =GenerationType.AUTO)
#Column(name="CustID")
private int CustID;
#Column(name="Mobile_No")
private String mobileno;
#Column(name="F_Name")
private String fname;
#Column(name="L_Name")
private String lname;
#Column(name="Email_Id")
private String emailid;
#Column(name="DOB")
private String dob;
#Column(name="Gender")
private String gender;
#Column(name="Acc_No")
private String accno;
#Column(name="Pwd")
private String Pwd;
#Column(name="present_address")
private String present_address;
#Column(name="permanent_address")
private String permanent_address;
#Column(name="occupation")
private String occupation;
#Column(name="marital_status")
private String marital_status;
#Column(name="adhaar_card_no")
private String adhaar_no;
#Column(name="pan")
private String pan;
#Column(name="Balance")
private String initial_bal;
#Column(name="status")
private String accstatus;
public String getAccstatus() {
return accstatus;
}
public void setAccstatus(String accstatus) {
this.accstatus = accstatus;
}
public int getCustID() {
return CustID;
}
public void setCustID(int custID) {
CustID = custID;
}
public String getMobileno() {
return mobileno;
}
public void setMobileno(String mobileno) {
this.mobileno = mobileno;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getEmailid() {
return emailid;
}
public void setEmailid(String emailid) {
this.emailid = emailid;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getAccno() {
return accno;
}
public void setAccno(String accno) {
this.accno = accno;
}
public String getPwd() {
return Pwd;
}
public void setPwd(String pwd) {
Pwd = pwd;
}
public String getPresent_address() {
return present_address;
}
public void setPresent_address(String present_address) {
this.present_address = present_address;
}
public String getPermanent_address() {
return permanent_address;
}
public void setPermanent_address(String permanent_address) {
this.permanent_address = permanent_address;
}
public String getOccupation() {
return occupation;
}
public void setOccupation(String occupation) {
this.occupation = occupation;
}
public String getMarital_status() {
return marital_status;
}
public void setMarital_status(String marital_status) {
this.marital_status = marital_status;
}
public String getAdhaar_no() {
return adhaar_no;
}
public void setAdhaar_no(String adhaar_no) {
this.adhaar_no = adhaar_no;
}
public String getPan() {
return pan;
}
public void setPan(String pan) {
this.pan = pan;
}
public String getInitial_bal() {
return initial_bal;
}
public void setInitial_bal(String initial_bal) {
this.initial_bal = initial_bal;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}

Error in One to many mapping in hibernate-spring integration

I need to map two pojo class using one to many, but getting the below error
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'testCaseStepsform' at row 1
When I saw the table created by hibernate, I found that a column with data type blob is created
I am adding the code below.
#Entity
#Table(name="TEST_CASE_DESC")
public class TestCaseForm implements Serializable{
/**
*
*/
private static final long serialVersionUID = 10001234L;
#Id
#Column(name="TEST_CASE_ID")
private String testCaseId;
#Column(name="PROJECT_NAME")
private String projectName;
#Column(name="PROJECT_ID")
private String projectId;
#Column(name="RELEASE_NAME")
private String releaseName;
#Column(name="RELEASE_ID")
private String releaseId;
#Column(name="ITERATION")
private String iteration;
#Column(name="TITLE")
private String title;
#Column(name="CREATED_BY")
private String createdBy;
#Column(name="CREATION_DATE")
private Date creationDate;
#Column(name="DESCRIPTION")
private String description;
#Column(name="PRE_CONDITION")
private String preCondition;
#Column(name="POST_CONDITION")
private String postCondition;
#Column(name="TYPE")
private String type;
#Column(name="IMPORTANCE")
private String importance;
private ArrayList<TestCaseStepsForm> testCaseStepsform = new ArrayList<TestCaseStepsForm>();
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPreCondition() {
return preCondition;
}
public void setPreCondition(String preCondition) {
this.preCondition = preCondition;
}
public String getPostCondition() {
return postCondition;
}
public void setPostCondition(String postCondition) {
this.postCondition = postCondition;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getRelease() {
return releaseName;
}
public void setReleaseName(String releaseName) {
this.releaseName = releaseName;
}
public String getReleaseId() {
return releaseId;
}
public void setReleaseId(String releaseId) {
this.releaseId = releaseId;
}
public String getIteration() {
return iteration;
}
public void setIteration(String iteration) {
this.iteration = iteration;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getReleaseName() {
return releaseName;
}
public String getImportance() {
return importance;
}
public void setImportance(String importance) {
this.importance = importance;
}
#OneToMany(mappedBy = "TEST_CASE_DESC", cascade = CascadeType.ALL)
public ArrayList<TestCaseStepsForm> getTestCaseStepsform() {
return testCaseStepsform;
}
public void setTestCaseStepsform(ArrayList<TestCaseStepsForm> testCaseStepsform) {
this.testCaseStepsform = testCaseStepsform;
}
public String getTestCaseId() {
return testCaseId;
}
public void setTestCaseId(String testCaseId) {
this.testCaseId = testCaseId;
}
}
#Entity
#Table(name="TEST_CASE_STEP")
public class TestCaseStepsForm implements Serializable{
/**
*
*/
private static final long serialVersionUID = 123456788091L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(name="SERIAL_NUMBER")
private String serialNumber;
#Column(name="TEST_CASE_ID")
private String testCaseId;
#Column(name="INPUT")
private String input;
#Column(name="EXPCETED_OUTPUT")
private String expectedOutput;
#Column(name="STATUS")
private String status;
private TestCaseForm testCaseForm;
public String getTestCaseId() {
return testCaseId;
}
public void setTestCaseId(String testCaseId) {
this.testCaseId = testCaseId;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getExpectedOutput() {
return expectedOutput;
}
public void setExpectedOutput(String expectedOutput) {
this.expectedOutput = expectedOutput;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
#ManyToOne( fetch = FetchType.LAZY)
#JoinColumn(name = "TEST_CASE_ID", nullable = false)
public TestCaseForm getTestCaseForm() {
return testCaseForm;
}
public void setTestCaseForm(TestCaseForm testCaseForm) {
this.testCaseForm = testCaseForm;
}
public String getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
}
#Configuration
public class TestCaseConfig {
#Bean(name="testCaseForm1")
public TestCaseForm testCaseForm1(){
TestCaseForm tst = new TestCaseForm();
tst.setTestCaseId("1122233");
tst.setProjectId("1234");
tst.setReleaseName("June");
tst.setReleaseId("1707");
tst.setIteration("2");
tst.setProjectName("ExpressPay");
tst.setTitle("ExpressPay");
tst.setCreatedBy("Anirban Deb");
tst.setCreationDate(new Date());
tst.setDescription("ExpressPay Login");
tst.setPreCondition("Active account");
tst.setPostCondition("success");
TestCaseStepsForm str1 = new TestCaseStepsForm();
str1.setTestCaseId("1122233");
str1.setInput("Hello World");
str1.setExpectedOutput("Bye Bye world");
str1.setStatus("Run");
str1.setTestCaseForm(tst);
TestCaseStepsForm str2 = new TestCaseStepsForm();
str2.setTestCaseId("1122233");
str2.setInput("Hello World");
str2.setExpectedOutput("Bye Bye world");
str2.setStatus("Run");
str1.setTestCaseForm(tst);
tst.getTestCaseStepsform().add(str1);
tst.getTestCaseStepsform().add(str2);
return tst;
}
}
public class Main {
public static void main(String[] args) throws MessagingException {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("core-bean.xml");
TestCaseForm test1 = context.getBean("testCaseForm1",TestCaseForm.class);
ITestCaseService testCase = context.getBean("testCaseServiceImp", ITestCaseService.class);
testCase.inserTestCase(test1);
[enter image description here][1]
stopWatch.stop();
System.out.println("Time taken in execution : "+stopWatch.getTotalTimeSeconds());
}
}
You should choose to annotate object properties or getters. Don't use it simultaneously.
Apart, #xl0e answer
You need to correct mapping
#OneToMany(mappedBy = "testCaseForm", cascade = CascadeType.ALL)
public ArrayList<TestCaseStepsForm> getTestCaseStepsform() {
return testCaseStepsform;
}

Categories