Reputation: 10043
I am building a web app built on Spring MVC and Hibernate. I have an existing domain model and the application is largely working.
I have a domain object called Status and a corresponding Spring Service class that contains standard CRUD methods you would expect (createStatus(Status s)
; etc..). The method to persist a new Status is currently working ok and is as follows:
@Transactional
public void createStatus(Status s) {
statusDao.persist(s);
}
Everything is happy and working fine. I then added a new Domain object called Notification and was having problems persisting the object to the DB (nothing was getting saved and no errors were logged) - so to test this, I temporarily tried creating a dummy Notification object and persisting it inside the createStatus() method (I know this is ugly - but the point was to attempt to persist it somewhere I know transactions are working and other objects are persisted - this is to rule out transactional issues).
The updated create method is as follows:
@Transactional
public void createStatus(Status s) {
statusDao.persist(s);
Notification n = new Notification();
getEntityManager().persist(n);
}
Now when I run it, the Status is still persisted but still the Notification object is not persisted and there are no errors in the log.
Has anyone experienced similar problems where specific Entities are not being persisted?
UPDATE:
Below are the Entities (Status and Notification) - it is annotation driven so no hbm files:
Status:
@Entity
@Table(name = "BF_STATUS")
@DiscriminatorValue("Status")
public class Status extends PersistableObject {
private static final long serialVersionUID = 4925606208793500282L;
@Column(name = "TITLE")
protected String title;
@Column(name = "DEADLINE")
private Date deadline;
@Column(name = "DETAILS")
@Lob
protected String details;
...
Accesors/Mutators
}
Notification:
@Entity
@Table(name = "BF_NOTIFICATION")
@DiscriminatorValue("notification")
public class Notification extends PersistableObject {
private static final long serialVersionUID = -8935712447903901463L;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "LINKED_ACTIVITY", nullable = true)
private Activity activity;
@Column(name = "notificationRead")
private boolean read = false;
...
Accessors/Mutators
}
Upvotes: 1
Views: 2190
Reputation: 20323
I have faced this issue sometime back reasons for this issue:
Database MySQL - Id was not marked as AutoIncrement
, and in my Service impl there was no catch block hence the exception was not logged.
Change in database semantics and again either no catch block or empty catch block with exception not being logged.
Incorrect log4j.xml which didn't log the exception at all!, and the exp.printStackTrace()
presented itself with the exception.
Now with this can you surround your code with valid try catch and see if there is something ?
Upvotes: 1