-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Foreign key constraint violation saving many-to-one field
PostPosted: Wed Jun 15, 2005 6:24 am 
Newbie

Joined: Sat Jun 11, 2005 5:27 am
Posts: 11
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.