HibernateTemplate Get method returns an object with null values

Firre :

I am encountering a strange problem with Hibernate. There are two database tables that stores active and resolved tickets. In Java there is a super class (Ticket) and entity subclasses (ActiveTicket and ResolvedTicket).

Now when a ticket is resolved it is moved to the ResolvedTicket table.

Now I have a custom findByID method where I try to first retrieve active ticket and then if I have a null object then I try to retrieve the resolved ticket. It looks like this:

public Ticket findByID(Long id) {
    Ticket t = findByID(ActiveTicket.class, id);
    if (null == t) {
        t = findByID(ResolvedTicket.class, id);
    }
    return t;
}

This is the custom findByID:

public <C> C findByID(Class<C> class, PK id) {
    return (C) getHibernateTemplate().get(class, id);
}

In my example, I have a ResolvedTicket stored in the database, when I call findByID() in the first snippet, the first line returns an object which contains null values. It looks like a proxy object but it is very strange because whenever I try to call any of it's getters I get a NullPointerException, which is strange because the object is not null when testing t == null.

This is how the object looks when getHibernateTemplate().get(ActiveTicket.class, id) is called: enter image description here

Firre :

The problem was with the version of Hibernate. After upgrading to a later version of Hibernate the issue went away.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=70955&siteId=1