File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Index in List collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Index in List collection" Watch "Index in List collection" New topic
Author

Index in List collection

Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
Hi all,

I want to use list collection in hibernate. List collection requires me to include index element in list. By default index element starts from 0 Position. My requirement is to index position at 1. Can you guys suggest me an idea?


ABU.A
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Why does this NEED to start at one?

Can't you just subtract one from your number each time?

Sean


I love this place!
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
I want to start the position of index from 1. Can i do it? Thats what my need is..
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Even if you start your object from 1, there will still be an element (probably null) at index 0, so if you have to iterate through a list you have that null.

What is your specific requirement that means it has to start from 1?
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
There is no specific need for my application. I wanted to set the position of index starting at 1. Thats it. If i can start index value at 1, i would be flattered...

Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

You can't well not without creating your own class to do that.
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
Hi sean, I got the answer to my question..What you suggested was fine and i can go for it..But I looked for actual solution..

And Hibernate got one now. I am sharing this bit of information because you might not know this (no problem if you already knew).

<list name="employee" lazy="true" inverse="true" cascade="all">
<key>
<column name="userId" />
</key>
<list-index column="start" type="java.lang.Date" base=1 />
<one-to-many class="com.jsportal.projectportal.portalBeans.Employment"/>
</list>


Thanks,
Abu.A
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Index in List collection