There are some mistakes in the your code:
@Embeded should be @Embedded in entity MyDTO1
@Embedable should be @Embeddable in entity MyDTO2
pulic class Test(){ should be public class Test{
ClientProgramINDTO.Class should be ClientProgramINDTO.class
So without fixing these compilation issues you cannot run the program.
Also, you have not provided what ClientProgramINDTO object is and how is it related to other entities, I am assuming that ClientProgramINDTO is same as MyDTO1.
If I proceed based on my assumption then there is no issue in the code. Here is the sample code that I have tried:
public class Test {
public static void main(String[] args) {
saveData();
testMethod();
HibernateUtil.getSessionFactory().close();
}
private static void saveData() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.getTransaction().begin();
ClientProgramINDTO c = new ClientProgramINDTO();
c.setInt1(1);
c.setMyDTO2(new MyDTO2("Test"));
session.save(c);
session.getTransaction().commit();
}
private static void testMethod() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.getTransaction().begin();
List<ClientProgramINDTO> clientProgramDto = session
.createCriteria(ClientProgramINDTO.class)
.add(Restrictions.eq("int1", 1))
.add(Restrictions.eq("myDTO2.string1", "Test")).list();
for (ClientProgramINDTO clientProgramINDTO : clientProgramDto) {
System.out.println(clientProgramINDTO.getInt1() + " "+ clientProgramINDTO.getMyDTO2().getString1());
}
session.getTransaction().commit();
}
}
Output of this program:
1 Test