Linked Questions
38 questions linked to/from Hibernate JPA Sequence (non-Id)
1 vote
0 answers
231 views
Java JPA - I need to auto generate value of field other than id [duplicate]
I'm working on employees database. Each one of them needs to have it's unique employee number in 5 digit format. It doesn't have to, but can be corelated with id number in database. I was trying to ...
0 votes
0 answers
159 views
H2 and Hibernate (JPA) -> GenerationType.IDENTITY after persisting [duplicate]
I use last H2 (current master) and Hibernate 5.14.14 as JPA provider. I have the following column in table: ID INT NOT NULL AUTO_INCREMENT and the following field in entity: @Column(name = "ID") @...
0 votes
0 answers
95 views
Spring + Hibernate wrong entity values on save [duplicate]
When I save a new entity on a MariaDB database with the PK and another field auto generated by the database, the entity is persisted correctly but the instance returned by Hibernate has inverted the ...
19 votes
3 answers
23k views
How to use UUIDs with Hibernate as a field?
I'm trying to use generated UUIDs without @Id annotation, because my primary key is something else. The application does not generate an UUID, do you have an idea? This is my declaration: @Column(...
10 votes
6 answers
28k views
How to use a sequence generator for a non ID field?
public class SequenceControlNumber extends SequenceGenerator { private static final Logger log = LoggerFactory.getLogger(SequenceGenerator.class); @Override public Serializable ...
6 votes
4 answers
36k views
JPA - Increment a numeric field through a sequence programmatically
I have a JPA 2 web application (Struts 2, Hibernate 4 as JPA implementation only). The current requirement is to add a (non-id) numeric sequential field, filled for certain rows only, to an existing ...
4 votes
3 answers
22k views
JPA or Hibernate to generate a (non primary key) column value, not starting from 1
I want a JPA/Hibernate (preferably JPA) annotation that can generate the value of a column, that is not a primary key and it doesn't start from 1. From what I have seen JPA cannot do that with @...
9 votes
5 answers
16k views
How can I access the repository from the entity in Spring Boot?
In a Spring Boot project I have a JPA entity, like this: @Entity public class Account { } and then I have the repository to query the database: public interface AccountRepository extends ...
7 votes
2 answers
32k views
Calling next value of a sequence in jpa
I have a class mapped as an Entity to persist it in a database. I have an id field as the primary key so every time the object is persisted the value of the id is retrieved from the sequence "...
7 votes
2 answers
5k views
AutoIncrement fields other than Id in grails
I'm new to Grails. I have a field in my domain object which I define as an String. String ponum When i click first time on create page ,the "ponum" field has to display 0001 and later it has to save ...
6 votes
1 answer
13k views
Auto generate unique random string in Spring MVC + Hibernate
Background I'm writing a project using Spring MVC (Framework v4.0.6.RELEASE, JPA v1.6.2.RELEASE) and Hibernate (Core v4.3.6.FINAL, JPA API v2.1). In my project, there are entities called 'Project'. ...
6 votes
2 answers
8k views
JPA: Usage of @GeneratedValue on non-id column
I am attempting to persist an entity with an attribute that I want to be populated from a DB sequence. I'm using Oracle, have created the sequence, verified the sequence works via sql, and yet my ...
4 votes
3 answers
7k views
Using Hibernate sequence generators manually
Basically, I want a way to access sequence values in a database-neutral way. The use case is that I have a field on an entity that I want to set based on an incrementing value (other than the id). ...
3 votes
2 answers
5k views
Generated value for nonPK field
I have the entity of some BusinessParticipant, it just simple flat entity. And these Participants may be organized in groups, by user's wish. The group has no data, just id. So creating entity and ...
3 votes
1 answer
5k views
@GeneratedValue doesn't work at non id field
I would like to make a unique field "number" with autogeneration(autoincrement, last number + 1). But it is not an id field. How can i reach that? @GeneratedValue doesn't work. Only id was generated. ...