-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Duplicate entry '' for key 'PRIMARY
PostPosted: Mon Dec 14, 2015 10:44 am 
Newbie

Joined: Mon Dec 14, 2015 10:36 am
Posts: 1
When I am trying to insert the data into the table I am getting this below error.

org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into messages(createdById, createdDate, lastAccessDate, lastUpdatedById, lastUpdatedDate, version, academicYearId, custId, message, desc , userId, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update.

Caused by: java.sql.BatchUpdateException: Duplicate entry '17431' for key 'PRIMARY'


I am using hibernate to save the entity.

The parent table is "Messages" and it has child classes and the mapping is like below.

@OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.ALL})
@JoinColumn(name="messageId")
public Set<MessageDetailsTracking> getMessageDetailsTracking() {
return messageDetailsTracking;


public Object save(Object messages) {
return dao.saveObject(messages);
}
Please help me to solve this issue


Top
 Profile  
 
 Post subject: Re: Duplicate entry '' for key 'PRIMARY
PostPosted: Mon Dec 14, 2015 10:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Can you add the child entity class and the logic that manages the associations prior to saving the parent.
It might be that the equals/hashCode are not properly implemented and you have a child twice in that Set.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.