Hibernate 2.l
I have a simple many-to-one field with an inverse Set on the other end:
Code:
<many-to-one class="jobfinder.data.Source" name="source" column="source_id">
<meta attribute="field-description">
Where job found
</meta>
</many-to-one>
When I try to save a new instance of this entity I'm getting the relevant foreign key constraint violated. I've checked. The
source property refers to a valid detatched entity from a previous session (I've tried locking the referenced entity without making any difference. I've checked the id in the referenced entity against the data base table and it's present OK. The SQL log I've managed to get from hibernate doesn't show me what's wrong because it's a prepared statement with ?s and I don't know how to see what values are substituted.
The code is straightforward, except that the entity may be new or a changed, existing one and I distiguish by looking for an id of zero.
Code:
form.save(job);
boolean isNew = job.getId() <= 0;
if(job.getSource() != null)
session.lock(job.getSource(), net.sf.hibernate.LockMode.READ);
if(job.getPrimaryContact() != null)
session.lock(job.getPrimaryContact(), net.sf.hibernate.LockMode.READ);
if(!isNew)
session.lock(job, net.sf.hibernate.LockMode.UPGRADE);
else
session.save(job);
fireEditListeners(new EditedEvent(job, isNew ? EditedEvent.EditType.Added : EditedEvent.EditType.Updated));
(I'm using Postgresql).
Is there some way I can log the substituted values for the SQL?
Has anyone had this problem?