Duplicate entry for key 'PRIMARY' With Play 1.5.0 + MySql
Ran into some trouble trying to upgrade 1.4.x to 1.5.0 - can't seem to find a migration guide?
After upgrading, when I save a class extending play.db.jpa.Model e.g.:
new Transaction(transDate, TransactionType.STOCK_BOUGHT, share, price, null).save();
The id of the record collides with existing entry and I get execeptions like:
Duplicate entry '9' for key 'PRIMARY'
At first it appeared to me that auto_increment of the table had been reset. But inserting manually worked fine.
Found this explanation: https://vladmihalcea.com/why-should-not-use-the-auto-jpa-generationtype-with-mysql-and-hibernate/
Should play.db.jpa.Model be updated to use native, or should I simply make my own Model class ala:
@MappedSuperclass public class MyModel extends GenericModel { @Id @GeneratedValue( strategy= GenerationType.AUTO, generator="native" ) @GenericGenerator( name = "native", strategy = "native" ) public Long id; ...
Try disabling the new hibernate ID generator by adding this option to application.conf:
hibernate.id.new_generator_mappings=false
More information: https://developer.jboss.org/thread/267613
Hi, Any idea of how to configure hibernate.id.new_generator_mappings=false in multi database environment ? hibernate.id.new_generator_mappings=false is working well for the primary database, but it not working for others databases configured in my project
Ps I have tried : db.database2.hibernate.id.new_generator_mappings=false database2.hibernate.id.new_generator_mappings=false ...
Hey man,
I work for a website for my school and our entire database was broken because we couldn't save anything. You have saved us all. You are a hero.
had the same issuce, thanks @ludovicofischer
Thank you @bastaware and @ludofischer for this thread, saved me hours!