Home » Support » Forum » Version 2.2.7 build 7/8 issue

Version 2.2.7 build 7/8 issue

#1

Hi all,

I have problems with builds 7 and 8 when trying to sort entities with mappedBy and my own method in query. This query "SELECT c FROM Customer c order by c.getNormalizedName()" returns List with null objects!

With builds 6 and 5 works it correctly. Removing mappedBy from @OneToOne(mappedBy = "address") also helps.

My code:

public class JavaApplication {
    public static void main(String[] args) {
        com.objectdb.Enhancer.enhance("javaapplication.*");
       
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("$objectdb/db/test.odb");
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();       
        Customer c = new Customer("1");
        Address a = new Address();
        c.setAddress(a);
        a.setCustomer(c);
        em.persist(c);
        em.getTransaction().commit();

        Query query = em.createQuery(
            "SELECT c FROM Customer c order by c.getNormalizedName()");
        List resultList = query.getResultList();
        System.out.println(resultList);

        em.close();
        emf.close();
    }
}


@Entity
public class Customer implements Serializable {
   
    private static final long serialVersionUID = 1L;

    @Id @GeneratedValue
    private Long id;
   
    @Basic(optional=false)
    private String name;
   
    @OneToOne(cascade= CascadeType.ALL, fetch= FetchType.EAGER, optional=false)
    private Address address;
   
    public Customer(String name){
        this.name = name;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
   
    public String getNormalizedName(){
        return Normalizer.normalize(name, Normalizer.Form.NFD);
    }
   
    @Override
    public String toString(){
        return name;
    }   
}


@Entity
public class Address implements Serializable {
   
    private static final long serialVersionUID = 1L;

    @Id @GeneratedValue
    private Long id;
   
    @OneToOne(mappedBy = "address")
    private Customer customer;

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}
#2

This is indeed a regression bug. Your code should work again with build 2.2.7_09.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login