-->
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.  [ 5 posts ] 
Author Message
 Post subject: Managing automatically an Index column in saveOrUpdate ()
PostPosted: Wed Apr 19, 2006 3:00 pm 
Newbie

Joined: Wed Apr 19, 2006 2:51 pm
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:MySQL 4.1.9

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

For a <one-to-many> relationship between 2 Objects, Hibernate requires for Lists an index column in the table of the child elements.
As explained in the documentation : “For lists, this column contains sequential integers numbered from zero. Make sure that your index really starts from zero if you have to deal with legacy data”.

Does Hibernate3 implement a mechanism to automatically generate / determine the index value to be set into the database_table.
If yes, howtodo ?

Thanks a lot for any hints that could help.
Cheers,
Laurent


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 3:16 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I don't think so. I just override the setList method

_________________
Chris

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


Top
 Profile  
 
 Post subject: Index column management in Save()
PostPosted: Wed Apr 19, 2006 5:51 pm 
Newbie

Joined: Wed Apr 19, 2006 2:51 pm
Posts: 16
Thanks Cris !

But what kind of a strategy would you advise for index management in your setList() method ?

Do you know whether hibernate enables to get the last index value without previously instantiating the list as it is able to do for primary keys ? or a mean to get the size() of the list still w/o instantiating the list ?

Thanks for your time and any additional hint that could help my search ?

cheers,
Laurent


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 6:36 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 2:26 pm
Posts: 28
You don't need to manage the index column for ordered collections! Just add the column to the mapping--Hibernate will use 0 for the first element in your list, and so on.

Read the manual --> http://www.hibernate.org/hib_docs/v3/re ... ns-indexed


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 6:44 pm 
Newbie

Joined: Wed Apr 19, 2006 2:51 pm
Posts: 16
Actually, I had read the manual (a couple of times ;-) ! We did add the column to the mapping ! I does work with SELECT (List()) when the index column is propely set with data.

Dealing with saving (INSERT) objects, the index column is not incremented by hibernate (the column remains with a null value) ; then, the SELECT does not work anymore !

_________________
Cheers,
Laurent

Thanks for rating in case it helped !


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.