This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Changing a Field to Auto-Generation Type after Table is already created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Changing a Field to Auto-Generation Type after Table is already created" Watch "Changing a Field to Auto-Generation Type after Table is already created" New topic
Author

Changing a Field to Auto-Generation Type after Table is already created

Anupama Sudhakaran
Greenhorn

Joined: Feb 22, 2010
Posts: 18
Hello,
How do i change a Field to Auto Number type in Oracle SQL Developer after i have already created the Table?
i want to use this to map a File in Hibernate. or do i have to write some Hibernate code?
Any help would be greatly appreciated.
Thank you in advance
Prabu Pidaran
Greenhorn

Joined: Feb 22, 2010
Posts: 19
Hello,

try adding the follwoing property in your hibernate mapping xml.

<generator class="increment">
</generator>


I think this would help you.
Anupama Sudhakaran
Greenhorn

Joined: Feb 22, 2010
Posts: 18
i did that but when im trying to put "native" as the generator class, its starting from any number like 21 or 41. i though tit must start from 1. is it not like that?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Anupama Sudhakaran wrote:i did that but when im trying to put "native" as the generator class, its starting from any number like 21 or 41. i though tit must start from 1. is it not like that?


Why must it start from one? Does your primary key also have business meaning?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Anupama Sudhakaran
Greenhorn

Joined: Feb 22, 2010
Posts: 18
no it doesnt. i am writing small programs a si have just started learning Hibernate. in Access, when we select auto number for a field, it usually begins with 1 and keeps incrementing. does it not happenlike that in Oracle?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No. Sequences are usually used in Oracle to back primary key generation, so all you really need to know from these is:
  • the number is unique
  • the numbers are in order

  • You get the same semantic meaning from 1,2,3,4 as you get from 1,45,877,678768. However there is a performance cost in keeping sequence numbers consecutive. Without any benefit, why do it?

    Anupama Sudhakaran
    Greenhorn

    Joined: Feb 22, 2010
    Posts: 18
    Thank you Paul
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Changing a Field to Auto-Generation Type after Table is already created