1

Is there any way to increment a key based on column rather than a row. i.e.:

ColA , ColB, ColC A , 1 , text3 B , 1 , text12 A , 2 , any text55 A , 3 , any text4 B , 2 , any text55 

When ColA contains same value then ColB value is incremented. Is there any way to do it via JPA or Hibernate rather than doing query of Max ?

4
  • As this is a JPA question, posting the relevant Entities might be useful.Is @OrderColumn of any use? docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html Commented Apr 14, 2016 at 12:39
  • When a record is inserted it's id should be incremented. as you can see ColB increment for ColA. Commented Apr 14, 2016 at 13:40
  • Then do you still think @OrderColumn will work? Is there any example? Commented Apr 15, 2016 at 5:22
  • Without the entities can't say. Commented Apr 15, 2016 at 6:41

1 Answer 1

1

i think you need to implement logic into the when you add a new item.

You can use @PrePersist annotatiom

Sign up to request clarification or add additional context in comments.

3 Comments

This is not an aswer, should be a comment
Then don't answer because this way your answer will be deleted, and start earning reputation to be able to comment.
I appreciate his answer @haytem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.