-->
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: Updates in Java SE environment
PostPosted: Thu Jul 13, 2006 12:41 pm 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
i'm having problems updating entities. when i update a managed object, changes are not propagated to the database.

should i define transaction boundaries to make updates happen?


here's the code:

Code:
EntityManagerFactory emf =
  Persistence.createEntityManagerFactory("spider");
EntityManager em = emf.createEntityManager();

RemoteFilePK id = new RemoteFilePK();
id.dir = "smb://localhost/spider/company2/";
id.name = "a11k";
RemoteFile f = em.find(RemoteFile.class, id);
f.setDescription("foobar "+new Date()); // not persisted to db


persistence.xml:

Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
  <persistence-unit name="spider">
    <non-jta-data-source>jdbc/spiderDS</non-jta-data-source>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
    </properties>
  </persistence-unit>
</persistence>


Top
 Profile  
 
 Post subject: Re: Updates in Java SE environment
PostPosted: Fri Jul 14, 2006 3:30 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
aspa wrote:
should i define transaction boundaries to make updates happen?

Yep.

Who manages transactions for you now?


Top
 Profile  
 
 Post subject: Re: Updates in Java SE environment
PostPosted: Tue Jul 18, 2006 2:24 pm 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
alesj wrote:
aspa wrote:
should i define transaction boundaries to make updates happen?

Yep.

Who manages transactions for you now?


no one, as far as i understand.

so, should i just use explicit transaction management like this?

EntityManagerFactory emf = Persistence.createEntityManagerFactory();
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
// read managed objects
// update managed objects
tx.commit();
} catch (RollbackException ex) { }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 2:29 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Yep.

Add a rollback into catch.
And close into finally.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 12:21 pm 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
alesj wrote:
Yep.

Add a rollback into catch.
And close into finally.


thanks!


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.