房间错误 - "Cannot figure out how to save this field into database. You can consider adding a type conve



我想存储用户在去电影院看电影时所做的class Reservation,但我不知道如何将其转换为房间可以将其存储在数据库中。

成员:places和codeQR出现错误。

类预订:

@Entity(tableName = "reservations", foreignKeys = @ForeignKey(entity = UtilizatorMADA.class, parentColumns = "id", childColumns = "idUser"))
public class Reservation implements Serializable {
@PrimaryKey(autoGenerate = true)
private long idReservation;
private long idUser;
@Embedded private Film film;
private Time startTime;
private List<Integer> places;
private Bitmap codeQR;

@Ignore
public Reservation(){}

public Reservation(long idReservation, long idUser, Film film, Time startTime, List<Integer> places, Bitmap codeQR) {
this.idReservation = idReservation;
this.idUser = idUser;
this.film = film;
this.startTime = startTime;
this.places = places;
this.codeQR = codeQR;
}

@Ignore
public Reservation(long idUser, Film film, Time startTime, List<Integer> places, Bitmap codeQR) {
this.idUser = idUser;
this.film = film;
this.startTime = startTime;
this.places = places;
this.codeQR = codeQR;
}

@Ignore
public Reservation(Film film, Time startTime, List<Integer> places, Bitmap codeQR) {
this.film = film;
this.startTime = startTime;
this.places = places;
this.codeQR = codeQR;
}

public long getIdReservation() {
return idReservation;
}

public void setIdReservation(long idReservation) {
this.idReservation = idReservation;
}

public long getIdUser() {
return idUser;
}

public void setIdUser(long idUser) {
this.idUser = idUser;
}

public void setPlaces(List<Integer> places) {
this.places = places;
}

public Film getFilm() {
return film;
}

public void setFilm(Film film) {
this.film = film;
}

public Time getStartTime() {
return startTime;
}

public void setStartTime(Time startTime) {
this.startTime = startTime;
}

public Bitmap getCodeQR() {
return codeQR;
}

public void setCodeQR(Bitmap codeQR) {
this.codeQR = codeQR;
}

public List<Integer> getPlaces() { return places; }

@Override
public String toString() {
return "Reservation{" +
"film=" + film +
", startTime=" + startTime +
", codeQR='" + codeQR + ''' +
'}';
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public boolean equals(Object o) {
if (this == o) return true;


if (o == null || getClass() != o.getClass()) return false;
Reservation that = (Reservation) o;
return Objects.equals(film, that.film) &&
Objects.equals(startTime, that.startTime) &&
Objects.equals(places, that.places);
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public int hashCode() {
return Objects.hash(film, startTime, places);
}
}

类电影:

@Entity(tableName = "films")
public class Film implements Serializable {
@PrimaryKey(autoGenerate = true)
private int idFilm;
private String title;
private String genre;
private String description;
private double rating;
private int imagePath;
private boolean isFavorite;
public Film(int idFilm, String title, String genre, String description, double rating, int imagePath, boolean isFavorite) {
this.idFilm = idFilm;
this.title = title;
this.genre = genre;
this.description = description;
this.rating = rating;
this.imagePath = imagePath;
this.isFavorite = isFavorite;
}
@Ignore
public Film(String title, String genre, String description, double rating, int imagePath) {
this.title = title;
this.genre = genre;
this.description = description;
this.rating = rating;
this.imagePath = imagePath;
isFavorite = false;
}
@Ignore
public Film(String title) {
this.title = title;
}
public int getIdFilm() {
return idFilm;
}
public void setIdFilm(int idFilm) {
this.idFilm = idFilm;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
public int getImagePath() {
return imagePath;
}
public void setImagePath(int imagePath) {
this.imagePath = imagePath;
}
public boolean isFavorite() {
return isFavorite;
}
public void setFavorite(boolean favorite) {
isFavorite = favorite;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Film film = (Film) o;
return Objects.equals(title, film.title);
}
@Override
public int hashCode() {
return Objects.hash(title);
}
}

我还通过ReservationOfMoviesDao得到以下错误,这可能是相关的,也可能不是。受影响的查询有:getReservationOfMoviesByUserId(长id), getReservationOfMovies()和getReservationOfMoviesByRservationId(长id);

错误:查询返回的列没有com.example.cinemaapp.model.ReservationMovie中的[idFilm]字段,即使它们被注释为非空或原语。查询返回的列:[idReservation,idUser,film,startTime,places,codeQR]

接口ReservationOfMoviesDao:

@Dao
public interface ReservationOfMoviesDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
void insert(ReservationMovie rm);
@Transaction
@Query("SELECT * FROM reservations where idUser = :id")
List<ReservationMovie> getReservationOfMoviesByUserId(long id);
@Transaction
@Query("SELECT * FROM reservations")
List<ReservationMovie> getReservationOfMovies();
@Transaction
@Query("SELECT * FROM reservations where idReservation = :id")
ReservationMovie getReservationOfMoviesByReservationId(long id);
}

如果你能帮我一下,我会很感激的。

你不能在其他实体中使用实体(例如Film in Reservation)。你应该使用"实体之间的关系"。或者试试"Embedded"注释。更多信息请参考此链接

相关内容