• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem incrementing the composite key

Surya Lanka
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have stuck with this problem.Please help me.

I have a table goals_01 in which ID and GOALCODE form a composite key in ORACLE DB.
I am using MyEclipse. I have selected increment as id generator while reverse engging from tables.
I thought id will be increment automatically but it gave me an error that you have assign id a value manually.
Since i dont have the max value in the begining i tried to get the max value of id by using HQL.below is the query.
Query query = hsession.createQuery("select max(Goals01.id) from Goals01 ");
List lis = query.list();
maxID = ((Integer)lis.get(0)).intValue();

here Goals01 is the pojo class.but i am getting a nullpointer exception at the 1st line.i thought since no value existed it is throwing an exception.
I inserted one row manually and tried again.but got the same .
Please help me to resolve this or any other way i can handle incrementing or assigning composite ids in hibernate.Example will be very helpful
Thanks in adavance
Mark Spritzler
Posts: 17309
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, "increment" is for a column type that auto-increments. Oracle does not have such a field type. They do have sequences, but that is completely different.

In your query for the Max, you use the name of the object. You aren't using an alias. Try using an alias in your query and see if that gets the query to work.

so for instance

Select max(a.id) from Table a

Also, you can create a sequence table in Oracle and have a query like

Select mySequence.nextVal from dual

Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!