New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullpointer Exception when using embedable in deep hierarchy #229

Closed
DrNickIT opened this Issue Sep 14, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@DrNickIT

Hi,

We currently get a NullPointerException when retrieving an embeddable field in a deep hierarchy.
We use:

* Hibernate 4.1.7
* QueryDSL 2.7.3

I created a little test to simulate the problem:

JPAQuery query = createDSLQuery();
query.from(parent);
query.where(parent.children.any().subChild.myEmbeddable.nummer.eq("Test"));
query.list(parent);

we get a NullpointerException because myEmbeddable is null

Now i even put QueryInit("*") on every field.

Here our entities

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class AbstractEntity implements Cloneable{

    @Id
    @Column(name = "ID")
    @GeneratedValue(generator="SEQUENCE")
    private long id;

    public long getId() {
        return id;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException{
        return super.clone();
    }
}

import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

import com.ardatis.domain.AbstractEntity;
import com.mysema.query.annotations.QueryInit;

@Entity
@SequenceGenerator(name = "SEQUENCE", sequenceName = "PARENT_SEQUENCE")
public class Parent extends AbstractEntity {
    @JoinColumn(name = "FK_PARENT_ID", nullable = false)
    @OneToMany(cascade = CascadeType.PERSIST)
    @QueryInit("*")
    private Collection<Child> children;

    public Parent() {
    }

    public Collection<Child> getChildren() {
        return children;
    }

    public void setChildren(Collection<Child> children) {
        this.children = children;
    }
}

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

import com.ardatis.domain.AbstractEntity;
import com.mysema.query.annotations.QueryInit;

@Entity
@SequenceGenerator(name = "SEQUENCE", sequenceName = "CHILD_SEQUENCE")
public class Child extends AbstractEntity {
    @OneToOne
    @JoinColumn(name = "FK_SUBCHILD_ID", referencedColumnName = "ID")
    @QueryInit("*")
    private SubChild subChild;

    public Child() {
    }

    public SubChild getSubChild() {
        return subChild;
    }

    public void setSubChild(SubChild subChild) {
        this.subChild = subChild;
    }
}

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;

import com.ardatis.domain.AbstractEntity;
import com.mysema.query.annotations.QueryInit;

@Entity
@SequenceGenerator(name = "SEQUENCE", sequenceName = "SUBCHILD_SEQUENCE")
public class SubChild extends AbstractEntity {
    @Embedded
    @QueryInit("*")
    private MyEmbeddable myEmbeddable;

    public SubChild() {
    }

    public MyEmbeddable getMyEmbeddable() {
        return myEmbeddable;
    }

    public void setMyEmbeddable(MyEmbeddable myEmbeddable) {
        this.myEmbeddable = myEmbeddable;
    }
}

import javax.persistence.Embeddable;

import com.mysema.query.annotations.QueryInit;

@Embeddable
public class MyEmbeddable {
    @QueryInit("*")
    private String nummer;

    public MyEmbeddable() {
    }

    public String getNummer() {
        return nummer;
    }

    public void setNummer(String nummer) {
        this.nummer = nummer;
    }
}
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 15, 2012

Member

The following annotation on the children property will now be enough to make your initialization case work

    @QueryInit("subChild.*")
    private Collection<Child> children;

It means that all fields of the child's subChild property should be initialized.

Member

timowest commented Sep 15, 2012

The following annotation on the children property will now be enough to make your initialization case work

    @QueryInit("subChild.*")
    private Collection<Child> children;

It means that all fields of the child's subChild property should be initialized.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 29, 2012

Member

Released in 2.8.0

Member

timowest commented Sep 29, 2012

Released in 2.8.0

@timowest timowest closed this Sep 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment