Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Jpa Primary key generation

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Jpa Primary key generation

    Hi All,
    I am using sql plus. whenever i am creating primary key with @generatedValue and @SequenceGenerator annotations .. it is not creating the sequence numbers... instead it creates
    random number like generation type.AUTO.. can anybody tell why it is happening?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Jpa Primary key generation

    This thread has been cross posted here:

    http://www.java-forums.org/advanced-java/52441-primary-key-generation-jpa-sequence-type.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Jpa Primary key generation

    Okay I understood the rules clearly, since i am new to this forum i did like that.. Can anybody Help me on this question?

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Jpa Primary key generation

    What is the data type of the field you trying to generate Primary Key for?

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Jpa Primary key generation

    Hi,
    thanks for replying..

    The data type is Integer..

    and the exact syntax i've written is,
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE,g enerator="xyz")
    @SequenceGenerator(initialValue=1,allocationSize=1 , name = "xyz", sequenceName="xyz")
    private int id;

    It should generate the sequence like 1,2,3... But actually it is creating the random numbers like 32,0,273,52,401..
    But my friends are telling that it will work fine with mySql .. But for sql plus it is not working...

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Jpa Primary key generation

    I can not say what exactly is the problem but i will recommend you to follow this as this might be helpful for you.
    ID Generation Type: SEQUENCE : Generated IDJPAJava Tutorial

  7. The Following User Says Thank You to Mr.777 For This Useful Post:

    rdheepan (December 13th, 2011)

Similar Threads

  1. Okay Here Goes...World and Map Generation.
    By rooster5105 in forum Algorithms & Recursion
    Replies: 1
    Last Post: October 30th, 2011, 02:45 PM
  2. Is AgileUnit the next test generation?
    By ricardo7307 in forum Member Introductions
    Replies: 0
    Last Post: May 16th, 2011, 02:33 PM
  3. Table with two primary keys(hibernate persistence)
    By jan_ed123 in forum Java Theory & Questions
    Replies: 0
    Last Post: August 20th, 2010, 02:36 AM
  4. auto-increment of primary key
    By hundu in forum Enterprise JavaBeans
    Replies: 1
    Last Post: May 15th, 2010, 10:55 AM