Saturday, 15 March 2014

java - Hibernate sequence generator always 0 -


I am trying to configure a mapped class to a postgres db in a sequence I used to define . When I try to remain any entities, the IDs are always zero when I use the nextval ('item_seq') selection, I will get 1 (or next val). I used intellij to rebuild classes, version 3.6.0 of Hibernate in this project, if it could be part of my problem?

@Entity @Table (name = "item") public class item {Private int itemid; @Basic @Id @SequenceGenerator (name = "item_seq", sequenceName = "item_seq", allocationSize = 1) @GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "item_seq") @column (name = "itemid", Unique = true, tap = false, insertable = true, updatable = true) public integer getItemid () {itemid returns; } ...}

experiment

  item items = new items (); Item.setCreated (new date ()); Item.setVendorId (vendorId); (Item) save; // is essentially foundBibernate Template () Save (Item.class.getName (), item);  

- Edit -

I am trying to give suggestions below and everything to generate 0 as an ID or exception to this class ID throwing should be handed manually before saving () 'This is where I am now, as a last ditch attempt, I tried to declare the variable instead of changing the lectures. Did not help

@ entity @Table (name = "item") public class items {@Id // @ SequenceGenerator (name = "item_seq", serial name = "item_sec", allocation size = 1) @ Generated Value (string = generation type.INTTI) //, generator = "item_sec") column @ (name = "item id", absolute = true, empty = false), insertable = true, updateable = true) Private long non-semiprecious; ... public long mitaimaid () {returns item id; It always works for me (though hibernate 4.x):

 < Code> @ ID @ Generated Values ​​(strategy = generation type. INNTITY) Private Long ID; The  

@ id column creates a primary key (unique, not a null), so you do not need @column (...) Is annotation your itemId setting somewhere? If you have one (Hibernate is not required) you can remove its setter


No comments:

Post a Comment