@@ -0,0 +1,2647 @@
+package com.vladmihalcea.hibernate.masterclass.laboratory.mapping;%0A%0Aimport com.vladmihalcea.hibernate.masterclass.laboratory.util.AbstractTest;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.*;%0Aimport java.io.Serializable;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0A/**%0A * CompositeIdWithManyToOneTest - CompositeIdWithManyToOneTest%0A *%0A * @author Vlad Mihalcea%0A */%0Apublic class CompositeIdWithManyToOneTest extends AbstractTest %7B%0A%0A    @Override%0A    protected Class%3C?%3E%5B%5D entities() %7B%0A        return new Class%3C?%3E%5B%5D %7B%0A                Car.class,%0A                Factory.class,%0A                CarFactory.class%0A        %7D;%0A    %7D%0A%0A    @Before%0A    public void init() %7B%0A        super.init();%0A        doInTransaction(session -%3E %7B%0A            Car car = new Car();%0A            car.transmission = %22Auto%22;%0A%0A            Car car1 = new Car();%0A            car1.transmission = %22Manual%22;%0A%0A            Factory factory = new Factory();%0A            session.persist(factory);%0A            session.persist(car);%0A            session.persist(car1);%0A%0A            CarFactory carFactory = new CarFactory();%0A            carFactory.setCar(car);%0A            carFactory.setFactory(factory);%0A%0A            CarFactory carFactory1 = new CarFactory();%0A            carFactory1.setCar(car1);%0A            carFactory1.setFactory(factory);%0A%0A            session.persist(carFactory);%0A            session.persist(carFactory1);%0A        %7D);%0A    %7D%0A%0A    @Test%0A    public void test() %7B%0A        doInTransaction(session -%3E %7B%0A            List%3CCarFactory%3E carFactoryList = session.createQuery(%22from CarFactory%22).list();%0A            assertEquals(2, carFactoryList.size());%0A        %7D);%0A    %7D%0A%0A    @Entity(name = %22Car%22)%0A    public static class Car implements Serializable %7B%0A%0A        @Id%0A        @GeneratedValue%0A        long id;%0A%0A        @Column(name=%22transmission%22, nullable = false)%0A        String transmission;%0A        @OneToMany(fetch = FetchType.LAZY, mappedBy = %22car%22)%0A        Set%3CCarFactory%3E factories;%0A    %7D%0A%0A    @Entity(name = %22Factory%22)%0A    public static class Factory  implements Serializable %7B%0A%0A        @Id%0A        @GeneratedValue%0A        long id;%0A    %7D%0A%0A    @Entity(name = %22CarFactory%22)%0A    public static class CarFactory implements Serializable %7B%0A%0A        @Id%0A        @ManyToOne%0A        @JoinColumn(name = %22transmission%22, referencedColumnName = %22transmission%22)%0A        Car car;%0A%0A        @ManyToOne%0A        @Id%0A        Factory factory;%0A%0A        public void setCar(Car car) %7B%0A            this.car = car;%0A        %7D%0A%0A        public void setFactory(Factory factory) %7B%0A            this.factory = factory;%0A        %7D%0A    %7D%0A%7D%0A

Add CompositeId test