Question: Is it possible to generate sequence number not using select someSequence from dual; ?
Problem : @GeneratedValue and @SequenceGenerator by default is using select someSequence from dual; to get nextval for my id. But my user doesn't have such rights to select from the dual table so I can use only id = sequence.nextval, but I don't know how to use this in Entity class. Or how should I pass id value to Entity constructor like sequence.nextval?
Usage: Oracle DB, CrudRepository, save() method.
You need to first create the sequence in Oracle:
CREATE SEQUENCE USER_SEQUENCE START WITH 1 INCREMENT BY 10;
Then annotate your class to look like this:
@Entity
@SequenceGenerator(name="USER_SEQUENCE_GENERATOR", sequenceName="USER_SEQUENCE", initialValue=1, allocationSize=10)
public class User {
@Id
@Column(name="USER_ID")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="USER_SEQUENCE_GENERATOR")
private Long userId;
}
I think you would need to write yout own strategy and use the GenericGenerator annotation. This answer might be helpful for you: link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With