-->
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: starting indexes at 1 instead of 0?
PostPosted: Wed Dec 15, 2004 1:15 pm 
Newbie

Joined: Fri Nov 05, 2004 2:13 pm
Posts: 7
Hi,
I'm saving a List/Set to a table, and each element's index in the List is also being saved. The indexes start at 0, but I'd like them to start at 1.

What's the best way to do this?

Thank you in advance for any advice.

Sincerely,

grimholtz


Here's my (shortened) hbm.xml:
Code:
<hibernate-mapping package="com.test.foo">
  <class name="QuickQuoteBean" table="quick_quote">
    <id name="quoteID" column="quick_quote_id">
    <generator class="increment"/>
  </id>
  <property name="quoteName" column="quick_quote_name"/>
  <list name="buildings" table="quick_quote_building">
    <key column="quick_quote_id"/>
    <index column="bldg_nmbr"/>
    <composite-element class="BuildingBean">
      <property name="zipCode"/>
      <property name="yearBuilt"/>
    </composite-element>
  </list>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 3:21 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
The indexes start at 0, but I'd like them to start at 1.


why because you don't have a record with 0?

i'm afraid you can't, if you don't really need ordered collection, use a bag

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 3:41 pm 
Newbie

Joined: Fri Nov 05, 2004 2:13 pm
Posts: 7
The table is used by a legacy application which expects numbering to start at 1. I do need an orderd collection, so a Bag won't work.

Is there no way to do this? What about using a Map whose keys are Integers (1-n) and whose values are the beans to be stored?

That seems like a kludge to me, but it's the only solution I can think of... would that work?

thank you,
grimholtz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 3:50 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what is bad in having the first element (index = 0) null?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 3:57 pm 
Newbie

Joined: Fri Nov 05, 2004 2:13 pm
Posts: 7
There are two applications using the same table. The old application cannot be changed, and it expects indexes to start at 1. The new application -- it uses Hibernate -- writes indexes starting at 0, breaking the old application.

In order for the new application (with Hibernate) to work with the old one, it must write indexes starting at 1.

Does that make sense?

Thanks,
grimholtz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 4:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
So why not follow anthony's suggestion and just have the first element in the collection (i.e., index=0) be null?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 4:11 pm 
Newbie

Joined: Fri Nov 05, 2004 2:13 pm
Posts: 7
ohhhh... I didn't understand that was his suggestion. Thanks! I'll give that a try. Much cleaner than the Map idea.

Thanks very much for your help!

grimholtz


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.