Hibernate errors: "java.lang.Integer cannot be cast to java.lang.String" and so on -
Hibernate errors: "java.lang.Integer cannot be cast to java.lang.String" and so on -
i have situation film can have lots of reviews, review ever related 1 movie. have had issue stated below, have tried many permutations, little confused, before mess code anymore thought best inquire here.
q.how should set up? can hard set movie_id int, in review before save review? or need have moviedto film object 1 of objects in reviewdto class? , when create review object saved, phone call review.setmovie(somemovieobject)?
so here going on in code errors:
first complained not-null film reference not set (hibernate : not-null property references null or transient value), after not beingness able prepare it, suggested remove constraint, see if work.
now complains "java.lang.integer cannot cast java.lang.string", confused there type mismatch? class<->hibernate or hibernate<->db?
very confused, can please shed light...? in advance.
package edu.unsw.comp9321.jdbc; public class reviewdto { private int id; private string review; private string rating; private int client_id; private int movie_id; public reviewdto() { } public reviewdto(int id, string review, string rating, int client_id, int movie_id) { super(); this.id = id; this.review = review; this.rating = rating; this.client_id = client_id; this.movie_id = movie_id; } public int getid() { homecoming id; } public void setid(int id) { this.id = id; } public string getreview() { homecoming review; } public void setreview(string review) { this.review = review; } public string getrating() { homecoming rating; } public void setrating(string rating) { this.rating = rating; } public int getclient_id() { homecoming client_id; } public void setclient_id(string client_id) { this.client_id = new integer(client_id); } public int getmovie_id() { homecoming movie_id; } public void setmovie_id(int movie_id) { this.movie_id = movie_id; } } bundle edu.unsw.comp9321.jdbc; import java.util.comparator; import java.util.hashset; import java.util.set; import javax.persistence.onetomany; public class moviedto implements comparable { private int id; private string title; private string poster; private string director; private string actors; private string synopsis; private string release_date; private int cinema_id; private set<genredto> genres = new hashset<genredto>(); private set<reviewdto> reviews = new hashset<reviewdto>(); private double rating; public moviedto() { } public moviedto(int id, string title, string poster, string director, string actors, string synopsis, string release_date, double rating) { super(); this.id = id; this.title = title; this.poster = poster; this.director = director; this.actors = actors; this.synopsis = synopsis; this.release_date = release_date; this.rating = rating; } public int getid() { homecoming id; } public void setid(int id) { this.id = id; } public string gettitle() { homecoming title; } public void settitle(string title) { this.title = title; } public string getposter() { homecoming poster; } public void setposter(string poster) { this.poster = poster; } public string getdirector() { homecoming director; } public void setdirector(string director) { this.director = director; } public string getactors() { homecoming actors; } public void setactors(string actors) { this.actors = actors; } public string getsynopsis() { homecoming synopsis; } public void setsynopsis(string synopsis) { this.synopsis = synopsis; } public string getrelease_date() { homecoming release_date; } public void setrelease_date(string release_date) { this.release_date = release_date; } public set<genredto> getgenres() { homecoming genres; } public void setgenres(set<genredto> genres) { this.genres = genres; } public set<reviewdto> getreviews() { homecoming reviews; } public void setreviews(set<reviewdto> reviews) { this.reviews = reviews; } public int getcinema_id() { homecoming cinema_id; } public void setcinema_id(int cinema_id) { this.cinema_id = cinema_id; } public double getrating() { homecoming rating; } public void setrating(double rating) { this.rating = rating; } @override public int compareto(object o) { moviedto other = (moviedto) o; if (this.rating > other.rating) homecoming -1; if (this.rating < other.rating) homecoming 1; homecoming 0; } } <?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="edu.unsw.comp9321.jdbc.reviewdto" table="review" > <id column="id" name="id"> <generator class="identity" /> </id> <property column="review" name="review" type="string" /> <property column="rating" name="rating" type="string" /> <property column="client_id" name="client_id" type="string" /> <property column="movie_id" name="movie_id" type="string" /> </class> </hibernate-mapping> <?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="edu.unsw.comp9321.jdbc.moviedto" table="movie" > <id column="id" name="id"> <generator class="identity" /> </id> <property column="title" name="title" type="string" /> <property column="poster" name="poster" type="string" /> <property column="director" name="director" type="string" /> <property column="actors" name="actors" type="string" /> <property column="synopsis" name="synopsis" type="string" /> <property column="release_date" name="release_date" type="string" /> <set name="genres" table="moviehasgenre" > <key column="movie_id" not-null="true" /> <many-to-many class="edu.unsw.comp9321.jdbc.genredto" column="genre_id" /> </set> <set name="reviews" table="review" > <key column="movie_id" /> <one-to-many class="edu.unsw.comp9321.jdbc.reviewdto" /> </set> </class> </hibernate-mapping>
the first error receive because define <key column="movie_id" not-null="true" />
means movie_id
can not null within genredto
of moviedto
. somewhere in code value null when trying persist (not plenty code shown tell where.)
the sec error because define <property column="movie_id" name="movie_id" type="string" />
in reviewdto
movie_id
int. should same.
as question, whether should utilize movie_id
or moviedto
in reviewdto
. depends on few things. bi-directional relationships fine (meaning reviewdto
has moviedto
attached while same moviedto
has same reviewdto
in it's list of reviews
. scale-ability , performance issues happen if have millions of entities. on contrary leaving movie_id
integer means anytime want moviedto
object reviewdto
have database call... may not costly because if bi-directional, phone call have happened regardless.
java hibernate
Comments
Post a Comment