N
news.t-com.hr
Lets say i have entity Car that has has FK to EngineType entity.
public class Car{
public EngineType type;
}
public class EngineType{
public Long engineTypeId;
}
and I want to persist Car. One way is to do find EngineType entity by ID
entityManager.find(EngineType.class, 999), set that to Car and persist Car,
and
the other way is to do this. Create new instance of engineType EngineType
newInstance = new EngineType(). Set id to it,
newInstance.setEngineTypeId(999),
than set that to Car, and persist ?
Both method works but which is more efficient, better ?
thanks in advance.
public class Car{
public EngineType type;
}
public class EngineType{
public Long engineTypeId;
}
and I want to persist Car. One way is to do find EngineType entity by ID
entityManager.find(EngineType.class, 999), set that to Car and persist Car,
and
the other way is to do this. Create new instance of engineType EngineType
newInstance = new EngineType(). Set id to it,
newInstance.setEngineTypeId(999),
than set that to Car, and persist ?
Both method works but which is more efficient, better ?
thanks in advance.