vu-hoang
(Vu Hoang)
March 23, 2016, 6:32am
1
Hi support
I working on Custom Event Business Logic.
I have class Booking and Itinerary
class Booking {
private Itinerary itinerary;
private String objectId;
}
when I call
Booking bookingResult = Backendless.Persistence.of(
Booking.class).save(booking);
It return error “Java.util.HashMap; cannot be cast to java.util.Collection”. But when I remove Itinerary in Booking class. It is normal.
Thanks
Best Regards
Do
Backendless.Data.mapTableToClass( "Booking", Booking.class );
before you save ‘booking’ and make sure that the getters and setters are present in Booking class for itinerary.
If it doesn’t help you, provide me full code of your Booking and Itinerary classes.
Regards,
Stanislav
vu-hoang
(Vu Hoang)
March 25, 2016, 3:44am
4
Hi Stanislav Yashchenko
I tried but still get same error. I attached 2 class files.
public class Booking {
private String objectId;
private String userId;
private Itinerary itinerary;
private Date bookedDate;
private String status;
private String paymentId;
private Date paymentDate;
private int numberOfGuest;
private String paidToGuild;
private Date datePayToGuild;
private double price;
private String currency;
public Booking() {
super();
}
public String getObjectId() {
return objectId;
}
public void setObjectId(String objectId) {
this.objectId = objectId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Date getBookedDate() {
return bookedDate;
}
public Itinerary getItinerary() {
return itinerary;
}
public void setItinerary(Itinerary itinerary) {
this.itinerary = itinerary;
}
public void setBookedDate(Date bookedDate) {
this.bookedDate = bookedDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getPaymentId() {
return paymentId;
}
public void setPaymentId(String paymentId) {
this.paymentId = paymentId;
}
public Date getPaymentDate() {
return paymentDate;
}
public void setPaymentDate(Date paymentDate) {
this.paymentDate = paymentDate;
}
public int getNumberOfGuest() {
return numberOfGuest;
}
public void setNumberOfGuest(int numberOfGuest) {
this.numberOfGuest = numberOfGuest;
}
public String getPaidToGuild() {
return paidToGuild;
}
public void setPaidToGuild(String paidToGuild) {
this.paidToGuild = paidToGuild;
}
public Date getDatePayToGuild() {
return datePayToGuild;
}
public void setDatePayToGuild(Date datePayToGuild) {
this.datePayToGuild = datePayToGuild;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
}
public class Itinerary {
private String objectId;
private String name;
private String createdBy;
private String createdDate;
private String description;
private int durationDay;
private int durationNight;
private int durationHour;
private double price;
private String currencyId;
private String itineraryType;
private String handicapFriendly;
private List<ItinerarySchedule> lstItinerary;
private List<Photo> lstPhoto;
private Location location;
private BackendlessUser owner;
private String status;
public Itinerary() {
}
public Itinerary(String name, String createdBy, String description,double price, String currencyId ,int durationDay, int durationNight, int durationHour, String itineraryType, String handicapFriendly) {
this.name = name;
this.createdBy = createdBy;
this.description = description;
this.durationDay = durationDay;
this.durationNight = durationNight;
this.durationHour = durationHour;
this.itineraryType = itineraryType;
this.handicapFriendly = handicapFriendly;
this.price = price;
this.currencyId = currencyId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getCreatedDate() {
return createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getDurationDay() {
return durationDay;
}
public void setDurationDay(int durationDay) {
this.durationDay = durationDay;
}
public int getDurationNight() {
return durationNight;
}
public void setDurationNight(int durationNight) {
this.durationNight = durationNight;
}
public int getDurationHour() {
return durationHour;
}
public void setDurationHour(int durationHour) {
this.durationHour = durationHour;
}
public String getItineraryType() {
return itineraryType;
}
public void setItineraryType(String itineraryType) {
this.itineraryType = itineraryType;
}
public String getHandicapFriendly() {
return handicapFriendly;
}
public void setHandicapFriendly(String handicapFriendly) {
this.handicapFriendly = handicapFriendly;
}
public String getObjectId() {
return objectId;
}
public void setObjectId(String objectId) {
this.objectId = objectId;
}
public List<ItinerarySchedule> getLstItinerary() {
return lstItinerary;
}
public void setLstItinerary(List<ItinerarySchedule> lstItinerary) {
this.lstItinerary = lstItinerary;
}
public List<Photo> getLstPhoto() {
return lstPhoto;
}
public void setLstPhoto(List<Photo> lstPhoto) {
this.lstPhoto = lstPhoto;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCurrencyId() {
return currencyId;
}
public void setCurrencyId(String currencyId) {
this.currencyId = currencyId;
}
public Location getLocation() {
return location;
}
public void setLocation(Location locationID) {
this.location = locationID;
}
public BackendlessUser getOwner() {
return owner;
}
public void setOwner(BackendlessUser owner) {
this.owner = owner;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
Thanks
vu-hoang
(Vu Hoang)
March 25, 2016, 4:48am
5
Hi
In Itinerary class have BackendlessUser field. When I remove it. It’s working.
In User I have relate to SpokenLanguage table. one to many relationship. So I add this code before save.
Backendless.Data.mapTableToClass("SpokenLanguage", SpokenLanguage.class);
Now it return error. “models.SpokenLanguage; cannot be cast to java.util.Collection”
I thinks it is root of error.
Thanks
Hi Vu,
Could you please export your data with relations and users and provide export archive?
Regards,
Denys
vu-hoang
(Vu Hoang)
March 25, 2016, 9:44am
7
Hi Denys KonakhevychCan I send you via email?
Thanks
Hi Vu,
Is there a stack trace with the error/exception?
Mark
Hi, Vu. Do you still reproduce this issue? If yes, what are the steps you follow?
That is what I’ve set up and it works without an error:
Backendless.setUrl( "https://api.backendless.com" );
Backendless.initApp( "APPID", "SECRETKEY", "v1" );
Backendless.Data.mapTableToClass("SpokenLanguage", SpokenLanguage.class);
Booking booking = new Booking();
booking.setCurrency( "$" );
booking.setNumberOfGuest( 1 );
// ...
Itinerary itinerary = new Itinerary();
itinerary.setCreatedBy( "me" );
itinerary.setCurrencyId( "someId" );
itinerary.setDurationDay( 13 );
itinerary.setHandicapFriendly( "Yes" );
// ...
booking.setItinerary( itinerary );
Booking bookingResult = Backendless.Persistence.of(Booking.class).save(booking);
System.out.println("Works fine");
vu-hoang
(Vu Hoang)
April 5, 2016, 1:02pm
11
Hi Anatolii Stepaniuk
Sorry I busy this week. I will back reproduce this issue next week.
Thanks for your support.