• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem incrementing the composite key

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic