Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Index in List collection

 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does this NEED to start at one?

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

Sean
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to start the position of index from 1. Can i do it? Thats what my need is..
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't well not without creating your own class to do that.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic