Hi
I've just started using Hibernate so this may appear as a naive question.
Let say I have 2 data objects: Server and Log.
a Server can have many logs and a Log belongs to one Server only.
Server has a serverId (sequence in PostgreSQL) and a Set getLogs() method. The method getLogs() uses lazy loading.
Log has a logId (sequence in PostgreSQL) and a Server getServer() method.
Now what's the best or recommended (for performance reason or correctness) way to create a new Log?
a)
Code:
server.getLogs().add(new Log());
session.update(server);
b)
Code:
Log log = new Log();
log.setServer(server);
session.save(log);
Also my understanding is that once a Server object is retrieved from the db and providing we're in session a call to getLogs() will lazy load the Set of Logs. Isn't that a performance hit when at some point the Set of Logs for a Server object will be huge?
I could probably have the same result by retrieving all Logs belonging to a Server with a from... where query.
It's far less obvious that I thought to break away from SQLish thinking ;)
Thanks.