Hibernate Entity not being persisted

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

}

Answers


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 didnt 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 ?


Need Your Help

Copy entire row from a sheet if value found in another sheet to third sheet

excel vba excel-vba

Trying to solve a problem with VBA/macro or Excel function, but haven't had any luck.

Google Maps - Set height and width for the infoWindow

google-maps infowindow

is it possible to set the height and the width for the google maps infoWindow?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.