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

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -