2

I have a class Account with a property number which has as value fe:

130.11.0000001

[plan_code].[year].[sequential number]

Now I have this number property mapped as a String. So when I want to create a second Account for the same Plan (code=130) it should get number = 130.11.0000002.

When an Account for plan(code=100) is made it should have number=100.11.0000001

I was thinking of using hilo generator from hibernate, but have no idea how to start and if this is even possible using hilo generator. So any pointers/ideas of implementation are welcome!

Maybe I should start making number property of type AccountNumber with as id a hilo generated value?

Nathan Q
  • 1,892
  • 17
  • 40
  • Do you have a database and are you already using Hibernate or are you just trying to use a Hibernate class to generate a unique id? – John B Nov 15 '11 at 12:49

2 Answers2

0

What about creating a class that implements account number as three fields and it's toString produces the combination? Then doing the increment is easy given the previous instance.

public class AccountNumber{
     public final int planCode;
     public final int year;
     public final int sequenceNumber;

     ...

     public static AccountNumber getNextSequenceNumber(AccountNumber previous)...
}
John B
  • 32,493
  • 6
  • 77
  • 98
  • but the sequenceNumber isn't unique, only the combination of plancode+year+sequencenumber is unique, so when an Account for plan(code=100) is made it should have number=100.11.0000001 – Nathan Q Nov 15 '11 at 12:31
  • Will you always have the most recent element for an plancode + year when you attempt to create the next one? If so, pass in that object, use it's plancode + year and increment the sequence number. If not, create a `Multimap>` where first key is planCode, second key is year. – John B Nov 15 '11 at 12:40
  • Or better yet `Table>` – John B Nov 15 '11 at 12:42
0

Take a look at this

You need to set the planCode and year by hand and let hibernate generate the sequenceNumber using a built in generator.

I have not tested though

Community
  • 1
  • 1
Liviu T.
  • 23,584
  • 10
  • 62
  • 58