Daily Archives: July 22, 2011

jpa mapping

java <-> oracle… with jpa sounds really easy, but was not… ok not really, because i just didnt get the whole thing… a problem was the naming… java class naming is different the database entities… so i needed to add mapping keywords…

@Entity
@Table (name=”<tablename>”, schema=”<schemaname>”)
public class <classname>{

@Id
@Column(name=”<colname>”)
private int id;

ok that was the simple part 🙂 the really hard part was the autoincrement… jpa allows different types of generatedValues and mainly it needs a specified sequence or trigger… the trigger is an absolute no go… and mapping sequence is wired… ok not soooo wired, but…

@Id
GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “<sequenceName>”)
@SequenceGenerator(name = “<sequenceName>”, initialValue = 1, allocationSize = 1)
@Column(name=”<colname>”)
private int id;

the strategy needs an generator, which know the sequence and its behavior… and allocationSize is the increment value… which is 50 as default…