Mapping to entity id with Hibernate
<p>Is there a way to map entities by their ID?</p>

<p>Currently i have a code that works liek this:</p>

<p>User object has some roles assigned to it:</p>

<pre><code>@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE})
@JoinTable(name = "USER_ROLES", joinColumns = {
        @JoinColumn(name = "USER_ID", nullable = false, updatable = false) },
        inverseJoinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) })
protected List&lt;Role&gt; assignedRoles = new ArrayList&lt;&gt;();
</code></pre>

<p>Role is mapped to users:</p>

<pre><code>@ManyToMany(fetch = FetchType.LAZY, mappedBy = "assignedRoles")
protected Collection&lt;? extends User&gt; users;
</code></pre>

<p>The thing is, what i want is something like:</p>

<pre><code>@ManyToMany(fetch = FetchType.LAZY, mappedBy = "assignedRoles")
protected Collection&lt;Integer&gt; users;
</code></pre>

<p>To operate userIds instead of User objects.</p>

<p>Is it possible to somehow configure Mapping to work this way? I failed to find anything on this in available Hibernate documentation.</p>