-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: persisting in J2SE
PostPosted: Thu Jul 27, 2006 1:09 pm 
Newbie

Joined: Wed Mar 08, 2006 8:11 am
Posts: 17
Location: Israel
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2 rc2

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: sqlserver 2005 express

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I am just starting out here. Finally got a connection to the database, and my queries don't throw exceptions, but when I try to persist, I don't get anything int he database. I am working on J2SE 5 - is there some kind of special way to access the entityManager so that the persist will get to the database?

thanks for the tips.

Code:
Book book = new Book("test");
      entityManager.persist(book);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 4:24 pm 
Beginner
Beginner

Joined: Wed Apr 26, 2006 2:41 pm
Posts: 30
That should work as soon as you commit... J2SE code usually defers the commit until the end. Show us all the code where you're getting the EntityManager and your entity mappings.


Top
 Profile  
 
 Post subject: here is my TestCase
PostPosted: Thu Jul 27, 2006 5:32 pm 
Newbie

Joined: Wed Mar 08, 2006 8:11 am
Posts: 17
Location: Israel
here's my test, quite simple.
The book class has a generated Integer id, and String title, both with corresponding get/set methods.

Code:
public class BookTest {
   private static EntityManagerFactory entityManagerFactory;
   private EntityManager entityManager;

   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
      try {
         entityManagerFactory = Persistence
               .createEntityManagerFactory("dnd");
      } catch (Exception e) {
         System.out.println(e);
      }
   }

   @AfterClass
   public static void tearDownAfterClass() throws Exception {
      if (entityManagerFactory != null) {
         entityManagerFactory.close();
      }
   }

   @Before
   public void setUp() throws Exception {
      entityManager = entityManagerFactory.createEntityManager();
   }

   @After
   public void tearDown() throws Exception {
      if (entityManager != null) {
         entityManager.close();
      }
   }

   @Test
   public void testPersistBook() {
      Book book = new Book("test");
      entityManager.persist(book);
   }

   @Test
   public void testGetBook() {
      List<Book> books = entityManager.createQuery(
            "from Book b where b.title = 'test'").getResultList();
      assertNotNull(books);
      System.out.println(books.size());
   }
}


The first test works, in that it doesn't throw any exceptions.
The second just shows there are 0 books in the database, and I also just check at the table itself to see it myself.
what can cause it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 2:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
em.getTransaction().begin()

_________________
Emmanuel


Top
 Profile  
 
 Post subject: thanks
PostPosted: Sat Jul 29, 2006 9:01 am 
Newbie

Joined: Wed Mar 08, 2006 8:11 am
Posts: 17
Location: Israel
that's what I needed..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.