java ee - How to store entity with relation without loading to memory other entities with hibernate -


i have 2 entities: myclassa , myclassb. second 1 big , havy.

@entity @table(name = tablea) public class myclassa {      @id     private long id;      @onetoone     @joincolumn(name = "id_b")     private myclassb connetctedb;      ... //some other values } 

i want create , store new entity of abouve class. service class pass values , id of myclassb entity. usual solutaion saw was:

public void createnewa(long idb, string name) {     myclassa = new myclassa();     a.setname(name);      myclassb b = getbbyid(idb); // <- want avoid     a.setconnetctedb(b);      entitymanager.persist(a); } 

the problem fact myclassb havy , operation getbbyid consume lot of resources. how can create , store new object of myclassa in case? have id of myclassb, should easy, whould have use native query, unfortunately hibernate not support native inserts.


Comments

Popular posts from this blog

swift - Button on Table View Cell connected to local function -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

c# - ajax - How to receive data both html and json from server? -