java - how to implement @GeneratedValue with my own strategy for generating keys -
i want implement own strategy generating primary keys new rows in table, example want id of host 172.24.85.20 8520.
can somehow extend @generatedvalue annotation? approach recommend?
10x in advance!
gal
in projects i'm using custom key, because need entities unique identity before persist() called. solution not using @generatedvalue annotation, initialize id-field manually. @generatedvalue annotation depends on database , primary key provider it. in case id field calculated , set before calling entitymanager.persist() or step can handled in @prepersist annotated entitylistener method (http://www.java2s.com/tutorial/java/0355__jpa/entitylistenerpreupdate.htm). apart extending annotations not possible (why not possible extend annotations in java?); combine annotations using stereotypes or create own annotations.
Comments
Post a Comment