dimanche 21 juin 2015

Get id column name from POJO, using reflection

@Entity
@Table(name="MY_TABLE")
public class MyTable{

    @Id 
    @Column(name="MY_TABLE_ID") 
    @GeneratedValue(strategy = GenerationType.AUTO ,generator="SQ_MY_TABLE")    
    @SequenceGenerator(name="SQ_MY_TABLE", sequenceName="SQ_MY_TABLE")
    private Long myTableId;

How can I, using reflection, get the primary key column name from my POJO, defined with the javax.persistence.Id annotation? I'd have to find the @Id and then get the name property of the @Column annotation... I'm not sure how to do that...

thanks!





Aucun commentaire:

Enregistrer un commentaire