# @OneToMany mapping cannot find the inverse attribute defined in "mappedBy"

**URL:** <https://discourse.hibernate.org/t/onetomany-mapping-cannot-find-the-inverse-attribute-defined-in-mappedby/7140>\
**Category:** Hibernate ORM\
**Created:** [January 13, 2023, 12:15pm UTC](https://discourse.hibernate.org/t/onetomany-mapping-cannot-find-the-inverse-attribute-defined-in-mappedby/7140 "2023-01-13T12:15:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![d00d](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@d00d](https://discourse.hibernate.org/u/d00d)\
**Post date:** [January 13, 2023, 12:15pm UTC](https://discourse.hibernate.org/t/onetomany-mapping-cannot-find-the-inverse-attribute-defined-in-mappedby/7140/1 "2023-01-13T12:15:06Z")

</div>

I have a **RmgtProfileBVOImpl** where I define a @OneToMany mapping:

```auto
@Entity
@Proxy(proxyClass = RmgtProfileBVO.class)
@Table(name = "rmgt_t_profile")
public class RmgtProfileBVOImpl extends AbstractBasePropertiesImpl implements RmgtProfileBVO {	

@OneToMany(mappedBy = "profileId",
			targetEntity = RmgtProfileValidationBVOImpl.class, 
			fetch = FetchType.EAGER, 
			cascade = CascadeType.ALL, 
			orphanRemoval = true)
	private java.util.Set<RmgtProfileValidationBVO> profileValidations = new HashSet<>();

```

I can see an error for profileId with this message:

> Can’t find inverse attribute

Problem is: the profileId is declared in the implementation ( **RmgtProfileValidationBVO** ), not in the interface. But I need the set in ProfileBVOImpl to be of interface-type .

This is what the **RmgtProfileValidationBVOImpl** looks like:

```auto
@Entity
@IdClass(RmgtProfileValidationId.class)
@Table(name = "rmgt_t_profile_validation")
@Proxy(proxyClass = RmgtProfileValidationBVO.class)
public class RmgtProfileValidationBVOImpl implements RmgtProfileValidationBVO {

	@Id
	@NotNull
	@Column(name="fk_profile_id", insertable = false, updatable = false)
	public Long profileId;

```

Is there a solution to this problem? I tried to work with **targetEntity** attribute but that did not help here.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [January 24, 2023, 8:13am UTC](https://discourse.hibernate.org/t/onetomany-mapping-cannot-find-the-inverse-attribute-defined-in-mappedby/7140/2 "2023-01-24T08:13:58Z")

</div>

The `mappedBy` attribute must refer to an attribute annotated with `@ManyToOne` that has the type of the owner of the `@OneToMany` i.e. `@Id @NotNull @ManyToOne(fetch = LAZY, targetEntity = RmgtProfileBVOImpl.class) @JoinColumn(name="fk_profile_id") RmgtProfileBVO profile;`, and then you use `@OneToMany(mappedBy = "profile")`
