-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Generic table id generator
PostPosted: Wed Jun 24, 2015 12:09 pm 
Newbie

Joined: Wed Jun 24, 2015 11:58 am
Posts: 2
Let's suppose a base entity like this

Code:
@MappedSuperclass
public abstract class AbstractEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "genericTableGenerator")
    @TableGenerator(name = "genericTableGenerator",
            table = "ID_GENERATOR",
            pkColumnName = "NAME",
            pkColumnValue = "ENTITY_GEN", // ??? dynamic way to specify this information ???
            valueColumnName = "VALUE")
    private long id;


used by a subclass like this

Code:
public Person extends AbstractEntity {


How could it be possible to have a fully database independent generator (table generator) having a sequence by entity type. The idea is to use the concrete class name as sequence name (AbstractEntity.class.getName()) BUT there is actually no way to specify this information at annotation level or make it dynamic!

So, what could be done except a weird override of generator (see MultipleHiLoPerTableGenerator#generate)


Top
 Profile  
 
 Post subject: Re: Generic table id generator
PostPosted: Wed Jun 24, 2015 12:30 pm 
Newbie

Joined: Wed Jun 24, 2015 11:58 am
Posts: 2
After having investigated a bit more, it looks this can simply be done by using the following code

Code:
@MappedSuperclass
public abstract class AbstractEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private long id;


So, it looks nothing particular has to be done.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.