0

I wanted to set auto increment id while sending data to the database.

I can do so by using annotations @Id and @generatedvalue. But I don't want that to use annotations.

Are there other ways to do achieve this?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 1
    And why do you not want to use annotations? There are ways but why? – Himanshu Bhardwaj Sep 11 '18 at 05:46
  • You can try to configure it via xml but this approach is deprecated, I think you shouldn't avoid using `@Id` and `@GeneratedValue` annotation because those annotation are used for other stuff than only increment in database. – Kamil W Sep 11 '18 at 06:11
  • you can make the db perform the autoincrement – Stultuske Sep 11 '18 at 06:13
  • I think its good to learn every way right bro...So i am trying to learn.By the way thanks for your suggestion.... – Amit yadav Sep 11 '18 at 06:22
  • Welcome to Stack Overflow! Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. Feel free to drop me a comment in case you have further questions or feedback for me. – GhostCat Sep 11 '18 at 07:13

2 Answers2

0

You can define a sequence in your database and xml config define it as

<id name="id" type="java.lang.Long" column="id">
    <generator class="sequence">
      <param name="sequence">tracks_seq</param>
    </generator>
</id>
0
<id name="employeeId" column="EMPLOYEE_ID">
    <generator class="increment"/>
</id>
Seymur Asadov
  • 612
  • 5
  • 19