Announcement Announcement Module
Collapse
No announcement yet.
Issue: Hibernate provides next generated id 32768 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 12:35 PM.
Working...
X