Chủ Nhật, 2 tháng 8, 2015

JPA 2.0: Mapping column

I setup a project JPA from open source database Sakila, download from MySQL.

With film_actor table, generated entity class with the its properties will throw exception when execute. To fix this exception, add MapsId with actorId and filmId:
Link: http://stackoverflow.com/a/29116687
    @EmbeddedId
    private FilmActorPK id;

    @Column(name="last_update")
    private Timestamp lastUpdate;

    //bi-directional many-to-one association to Actor
    @ManyToOne
    @MapsId("actorId")                         // add FilmActorPK's actorId property
    @JoinColumn(name="actor_id")
    private Actor actor;

    //bi-directional many-to-one association to Film
    @ManyToOne
    @MapsId("filmId")                         // add FilmActorPK's filmId property
    @JoinColumn(name="film_id")
    private Film film;

Link: http://www.developerscrappad.com/228/java/java-ee/ejb3-jpa-dealing-with-date-time-and-timestamp/

Error:
Caused by: org.hibernate.MappingException: property mapping has wrong number of columns: vn.store.jpa.domain.Film.releaseYear type: object

Fix by change:
    @Column(name="release_year")
    @Temporal(TemporalType.TIMESTAMP) // add
    public Date releaseYear; // add
//    private Object releaseYear;

Continue ...



- Comments

0 nhận xét:

Đăng nhận xét