SomethingsGottaGive
SomethingsGottaGive

Reputation: 1894

JPA giving a unknown entity reference

My project is using JPA2/hibernate to map properties to their respective tables. As I understand it, I must put the property mappedby in the owner table and put JoinColumn in the child table(many side). I am getting the error as seen here:

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: ninja.familyhomestay.domain.HouseImage.homestay_info in ninja.familyhomestay.domain.HomestayInfo.houseImages

Here is my HomestayInfo class:

@Entity
@Table(name = "homestay_info")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "homestay_info")
data class HomestayInfo(
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    var id: Long? = null,

    ...

    @OneToMany(mappedBy = "homestay_info", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
    var houseImages: MutableSet<HouseImage> = HashSet(),
...
) 

and my houseImage class:

@Entity
@Table(name = "house_image")
@Document(indexName = "house_image")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
class HouseImage(
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    var id: Long? = null,
...
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name = "homestay_info_id")
    var homestayInfo: HomestayInfo? = null
) : Serializable 

Any ideas? I am also using liquid to create the tables in the db.

Upvotes: 1

Views: 45

Answers (1)

codeLover
codeLover

Reputation: 2592

In your HomestayInfo class, while mentioning @OneToMany relationship, you are mentioning value of mappedBy attribute as homestay_info, while in HouseImage class there is no field with the name homestay_info.

You should have same field name mentioned in mappedBy and the attribute specifying the bilateral relationship in the other class.

Either rename homestayInfo to homestay_Info in the below statement :

var homestayInfo: HomestayInfo? = null

or

rename the value in mappedBy field to homestayInfo

Upvotes: 1

Related Questions