Hi,
if the realtions are set to lazy hibernate don't retrieves them, while it creates the proxy. Normally the proxy contains only the primary key and the @Basic attributes plus
@OneToOne (cause the default is eagger here).
In your case you changed the default or the @OneToMany relations aren't loaded by the default.
To make it easier I focus on the @OneToOne case.
So your Proxy don't contains that object, cause it was set to lazy. If you try to retrieve the id, you normally have to get that Object before. So hibernate is forced to load it from the database, which implies an SQL-Query.
If your Object is persistent (e.g. cause you called save() before) , Hibernate where forced to load everything before to check if your Object is dirty or not. So if you request the id of an relationship, it was already loaded before, so no new SQLQuery is needed. If you have accessed the object before it is also already loaded.
org.hibernate.Session.getIdentifier() works only if the object was already loaded before.
Quote:
Return the identifier value of the given entity as associated with this session. An exception is thrown if the given entity instance is transient or detached in relation to this session.
In your case
org.hibernate.proxy.LazyInitializer
Quote:
Get the identifier held by the proxy
also you call that statement on the id (getId()), so the cast to HibernateProxy and the call of getHibernateLazyInitializer().getIdentifier() makes no sence for me.
"<objet persistent>.get<objet associƩ>()" will cause an SQL-Statement if not loaded before. Otherwise not.
Hibernate does not know, that you only need the ID, which is probably already loaded, cause the foreign key is part of the same table and not the whole object. (Only OneToOne or ManyToOne, OneToMany is mapped on the other side or by join-table)
I don't known, if you can retrieve the foreign key, without loading the object. but as long you don't use a natural key, it s very likely that it is worthless anyway.
Hope this helps.
Greetings Michael