Reputation: 343
I just entered a project which is using Spring for persisting everything. For the id column @GeneratedValue is used. I imported data from another database using SQL and now the auto increased generated value is out of sync.
The Backend which is using Spring is running on a Java Web Tomcat 7 Server which is running on the HANA Cloud Platform.
Does someone know, where it saves this generated value and how I increase it so it uses id's that are above the ones I inserted via SQL?
Thank you very much and kind regards, tietze111
EDIT: We are using a HANA Database and here is some code, hope this is what you are looking for:
public abstract class AbstractModel<ID extends Serializable> implements Serializable {
private static final long serialVersionUID = -3275552243704225648L;
@Id
@GeneratedValue
@JsonView(View.Summary.class)
protected ID id;
[...]
EDIT 2 (More information, don't know if that's helpful?): We are using hibernate but the problem is that the sequence doesn't show up in the system. There is a table called SEQUENCE but is just has a fixed SEQ_COUNT attribute. The value of it is always 50. The SEQ_NAME attribute has the value "SEQ_GEN". The table has only 1 entry. This is how the definition looks like this. The picture also shows that there is no sequence.
SOLUTION: Found this thread on stackoverflow and altered the generation strategy to GenerationType.TABLE . Now I was able to change the id in the table easily.
Upvotes: 0
Views: 782
Reputation: 343
Found this thread about the meaning of generation strategies on stackoverflow and altered the generation strategy to GenerationType.TABLE . Now I was able to change the id in the table easily.
Thanks to Neil Stockton whose comment brought me in this direction!
Upvotes: 1
Reputation: 679
This is really a SQL/DDL question.
You need to look at the DDL of your database and find out what the sequence name is. Then you will have to update the high value. The default name in hibernate is hibernate_sequence, but yours may vary by JPA provider.
alter sequence <sequence name> restart with <new starting value>;
If you're using an auto_increment column, you update it by altering the table. See http://www.tutorialspoint.com/sap_hana/sap_hana_sql_sequences.htm
Upvotes: 0