-->
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.  [ 7 posts ] 
Author Message
 Post subject: one-to-many not picking up parent key? Integrity violation!
PostPosted: Thu Oct 20, 2005 11:25 am 
Newbie

Joined: Thu Oct 20, 2005 11:09 am
Posts: 5
Location: Natick, MA
Description of problem: When using the code below, I'm getting an Integrity Violation when trying to save the encapsulating class. The exception is thrown on the tx.commit() line.

Looking at the data actually stored into the database via the HSQL command line, I see the WorkingSet created, I see either none or 1 of the WorkingTasks created, but the set_id is 'null'. For some reason when doing the new WorkingTask() and save()ing it, the set_id column (though the column -is- there... so something's working), is not getting the value of the 'owning' WorkingSet'. I believe I'm setting up something wrong in the Set definition, but I'll be darned if I can figure out what it is.

My apologies for the size of the post and the dump here, but this is a somewhat critical-path issue right now, and I've STFW'ed, RTFM'ed, and every other acronym I can think of (including talking to a lot of people on IRC :)

Thanks for any help you can provide.

Hibernate version: 3.0

Mapping documents:
<class name="com.arete.JQuo.WorkingSet" table="workingsets">
<id name="id" column="set_id" type="long">
<generator class="increment"/>
</id>
<property name="owner" column="ws_name" type="string" />
<property name="comment" column="ws_note" type="string" />
<property name="checkedout" column="ws_added" type="timestamp" />

<set name="tasklist" cascade="all" >
<key column="set_id" not-null="true" />
<one-to-many class="com.arete.JQuo.WorkingTask"/>
</set>

</class>

and

<class name="com.arete.JQuo.WorkingTask" table="ws_tasks">
<id name="id" column="task_id" type="long">
<generator class="increment"/>
</id>
<property name="name" column="task_name" type="string" />
<property name="note" column="task_note" type="text" />
<property name="added" column="task_added" type="timestamp" />
(snip... this is a long class)
<property name="parenttask" column="task_parenttask" type="integer" />

</class>


Code between sessionFactory.openSession() and session.close():
Session session = myFactory.openSession();
tx = session.beginTransaction();
log.info("Creating the working set...");
mySet = new WorkingSet();
mySet.setowner(setUser);
session.save(mySet);
newId = mySet.getId();
log.info("ID of newly created working set is " + newId);
tx.commit();
tx = session.beginTransaction();
log.info("Fetching the Tasks...");
Query query = session.createQuery("from Task");
for (Iterator it = query.iterate(); it.hasNext();) {
task = (Task) it.next();
wTask = new WorkingTask();
wTask.setname(task.getname());
wTask.setnote(task.getnote());
log.info("wTask is " + wTask.toString());
log.info("wTask name is " + wTask.getname());
log.info("wTask note is " + wTask.getnote());
taskRows.add(wTask);
}
mySet.settasklist(taskRows);
session.saveOrUpdate(mySet);
tx.commit();
session.close();

Full stack trace of any exception that occurs:
11:00:07,650 INFO [STDOUT] Hibernate: insert into ws_tasks (task_name, task_note, task_added, task_reqorgid, task_reqwhoid, task_installid, task_licenseid, task_app, task_module, task_categories, task_folder, task_woid, task_sharepct, task_due, task_release, task_stat, task_ownwhoid, task_stepownid, task_stepitem, task_billrate, task_stepstat, task_comments, task_closed, task_parenttask, set_id, task_id) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
11:00:07,838 WARN [JDBCExceptionReporter] SQL Error: -177, SQLState: 23000
11:00:07,838 ERROR [JDBCExceptionReporter] Integrity constraint violation - no parent FKB5C5586B389BB6BD table: WORKINGSETS in statement [insert into ws_tasks (task_name, task_note, task_added, task_reqorgid, task_reqwhoid, task_installid, task_licenseid, task_app, task_module, task_categories, task_folder, task_woid, task_sharepct, task_due, task_release, task_stat, task_ownwhoid, task_stepownid, task_stepitem,task_billrate, task_stepstat, task_comments, task_closed, task_parenttask, set_id, task_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
11:00:07,839 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [com.arete.JQuo.WorkingTask]
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

Name and version of the database you are using: HSQL - er, whatever comes iwth JBoss 4.0.2.

The generated SQL (show_sql=true): In the trace above.

Debug level Hibernate log excerpt: This I do not have, though I think the dump above is complete enough.

_________________
----
<a href="http://planet-geek.com/">Planet Geek!</a>


Top
 Profile  
 
 Post subject: Re: one-to-many not picking up parent key? Integrity violat
PostPosted: Thu Oct 20, 2005 2:38 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
dbs wrote:
11:00:07,838 ERROR [JDBCExceptionReporter] Integrity constraint violation - no parent FKB5C5586B389BB6BD table: WORKINGSETS in statement [insert into ws_tasks ....


Do have all your database tables and columns in place? Looks like you're missing something...

jd


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:43 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I think there is a better order to what you're doing that might help. No need to save it then update it. Seems like unnecessary amount of db calls.

Session session = myFactory.openSession();

Query query = session.createQuery("from Task");

for (Iterator it = query.iterate(); it.hasNext();) {
task = (Task) it.next();
wTask = new WorkingTask();
wTask.setname(task.getname());
wTask.setnote(task.getnote());

taskRows.add(wTask);
}

mySet = new WorkingSet();

mySet.setowner(setUser);
mySet.settasklist(taskRows);

session.save(mySet);

session.flush();
session.close();

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject: Re: one-to-many not picking up parent key? Integrity violat
PostPosted: Thu Oct 20, 2005 5:44 pm 
Newbie

Joined: Thu Oct 20, 2005 11:09 am
Posts: 5
Location: Natick, MA
jd001982 wrote:
Do have all your database tables and columns in place? Looks like you're missing something...


Yes, Hibernate is set up to automatically create / update tables as necessary. So it's doing so without me doing the alter table / create table commands on my own. I agree it looks like it's missing something - or more to the point, it's tryign to refer to a foreign key that isn't there or is minamed. I just can't figure out what it is.

_________________
----
<a href="http://planet-geek.com/">Planet Geek!</a>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 6:18 pm 
Newbie

Joined: Thu Oct 20, 2005 11:09 am
Posts: 5
Location: Natick, MA
kochcp wrote:
I think there is a better order to what you're doing that might help. No need to save it then update it. Seems like unnecessary amount of db calls.


While I appreciate the commentary, it's not really fixing the problem. I even replaced the large block with block you've given me, and the same result happens.

I think the problem is in my hibernate defs... something is simply not populating the set_id row in for each of the Ws_Tasks being created.

Help!

_________________
----
<a href="http://planet-geek.com/">Planet Geek!</a>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 11:13 pm 
Newbie

Joined: Thu Oct 20, 2005 11:09 am
Posts: 5
Location: Natick, MA
Update!

I switched my hibernate.cfg.xml file over to use the MySQL instance I have on the same machine, and re-ran the app, and it worked right off the bat. This is pointing to a problem with Hypersonic (HSQL).

I hope the Hibernate / JBoss folks will look at this and come up with a fix.

_________________
----
<a href="http://planet-geek.com/">Planet Geek!</a>


Top
 Profile  
 
 Post subject: Possible solution
PostPosted: Fri Dec 16, 2005 6:32 pm 
Newbie

Joined: Thu Oct 21, 2004 7:02 am
Posts: 14
Hi,

Don't know if this will help your case, but I had a similar problem (same error) using hsqldb. I changed the value of the <key column="..."> element of my set mapping to something else than the same as for the key column of the parent, that solved the problem...

--
Cheers,
Kristian


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

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.