Results 1 to 1 of 1

Thread: Issue: Hibernate provides next generated id 32768

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Default Issue: Hibernate provides next generated id 32768

    (yet another newbie using roo+hibernate)

    The problem i had to deal with is the following...
    I have created an abstract class Event and its Inheritance Strategy = TABLE_PER_CLASS.
    Code:
    @RooJavaBean
    @RooToString
    @RooJpaActiveRecord(inheritanceType = "TABLE_PER_CLASS")
    @RooJson
    public abstract class Event {
    ...
    }
    And subclasses extending Event: Rating, Tagging.
    Code:
    @RooJavaBean
    @RooToString
    @RooJson
    @RooSolrSearchable
    @RooJpaActiveRecord(table = "ratings", finders = { "findRatingsByUser"})
    public class Rating extends Event {
    ...
    }
    Start the server

    Create Rating -> id = 1
    Create Tagging -> id = 2

    Restart the server

    Create Rating -> id = 32768
    Create Tagging -> id = 32769

    Restart the server again

    Create Rating -> id = 65536
    Create Tagging -> id = 65537

    Each time i restart the server the next generated id provided by hibernate starts from restart_time*32768.

    After searching I found out that Hibernate caches a block of ids for performance issues, read this http://stackoverflow.com/questions/2...ationtype-tabl

    Solution:
    (Push in Id from *_Roo_Jpa_Entity.aj)
    Set the allocationSize you prefer and any other param, but dont forget the performance issues.
    In development mode it s ok to set it equal to 1
    Code:
    @RooJavaBean
    @RooToString
    @RooJpaActiveRecord(inheritanceType = "TABLE_PER_CLASS")
    @RooJson
    public abstract class Event {
        
        @Id
        @GeneratedValue(strategy = GenerationType.TABLE, generator="generatorName")  
        @TableGenerator(name="generatorName", allocationSize=1)
        @Column(name = "id")
        private Long id;
        ...
    }
    Proposal:
    Not sure but i think it would be helpful Roo to include TableGenerator in the *_Roo_Jpa_Entity.aj, in order the developer to be aware of such issues.
    (Btw the default value of allocationSize in TableGenerator is 50)

    Any comment(s) more than welcome!!
    GK
    Last edited by kalabakas; Nov 13th, 2012 at 11:35 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •