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
< 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