Search in sources :

Example 1 with BlogPost

use of org.baeldung.querydsl.intro.entities.BlogPost in project tutorials by eugenp.

the class QueryDSLIntegrationTest method populateDatabase.

@BeforeClass
public static void populateDatabase() {
    emf = Persistence.createEntityManagerFactory("org.baeldung.querydsl.intro");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    User user1 = new User();
    user1.setLogin("David");
    em.persist(user1);
    User user2 = new User();
    user2.setLogin("Ash");
    em.persist(user2);
    User user3 = new User();
    user3.setLogin("Call");
    em.persist(user3);
    User user4 = new User();
    user4.setLogin("Bishop");
    em.persist(user4);
    BlogPost blogPost1 = new BlogPost();
    blogPost1.setTitle("Hello World!");
    blogPost1.setUser(user1);
    em.persist(blogPost1);
    BlogPost blogPost2 = new BlogPost();
    blogPost2.setTitle("My Second Post");
    blogPost2.setUser(user1);
    em.persist(blogPost2);
    BlogPost blogPost3 = new BlogPost();
    blogPost3.setTitle("Hello World!");
    blogPost3.setUser(user3);
    em.persist(blogPost3);
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) QUser(org.baeldung.querydsl.intro.entities.QUser) User(org.baeldung.querydsl.intro.entities.User) BlogPost(org.baeldung.querydsl.intro.entities.BlogPost) QBlogPost(org.baeldung.querydsl.intro.entities.QBlogPost)

Aggregations

EntityManager (javax.persistence.EntityManager)1 BlogPost (org.baeldung.querydsl.intro.entities.BlogPost)1 QBlogPost (org.baeldung.querydsl.intro.entities.QBlogPost)1 QUser (org.baeldung.querydsl.intro.entities.QUser)1 User (org.baeldung.querydsl.intro.entities.User)1