I don’t know how to do this “cleanly”, neither with JPA, nor with Hibernate, nor with any other provider. You can achieve what you want with a special SQL query, though (similar to this question ):
@Entity
@Table(name="tag")
@SQLInsert( sql="INSERT INTO tag(name, count) VALUES (?, ?)
ON DUPLICATE KEY UPDATE set count = count + 1")
public class Tag {}
Now, unfortunately, you are associated with both Hibernate and MySQL. You can change the sql syntax for other databases: s and / or use stored procedures, try updating first, insert a crash, etc. Everyone has their drawbacks, so it would be convenient if the JPA support this, but alas.
, JPA , .