>-----Original Message----- >From: Chris Geer [mailto:[email protected]] >Sent: Thursday, October 04, 2012 8:17 PM >To: dev >Subject: Re: JPA Save Question > >On Thu, Oct 4, 2012 at 11:45 AM, Chris Geer <[email protected]> wrote: > >> I'm having an issue with JPA and I'm hoping someone can help me out. As >> part of the object model restructure we are splitting some of the object >> dependencies and replacing them with IDs. For example, we are breaking the >> link between WidgetTag and Tag and having WidgetTag have a TagID. This >> means that when a new WidgetTag is created the system needs to create the >> new Tag object if it doesn't exist, get it's ID and then save the WidgetTag >> with the TagID. My problem is that when I create a new Tag and call >> TagRepository.save(tag), it "saves" but when it returns the Tag object it >> doesn't container an ID, but it's now a JPATag object. Is there a way to >> resolve that or do we need to do a save, then a get to return a fully >> populated object? > > >Additional information: It looks like when the entity comes back from the >entityManager.persist method it's detached. I've tried to figure out how to >correct that but I can't quite seem to figure it out. Any thoughts? >
Hi Chris, in the past whenever I've experienced this behavior with JPA, its *usually* because the transaction hasn't been committed yet. And *usually* it's because I forgot to annotate the service layer with @Transactional. If you tune up the JPA logging level, you should see an INSERT or UPDATE statement logged out. If you don't ever see the actual INSERT or UPDATE SQL statement, that's a good sign that the transaction isn't getting committed, usually because of a missing @Transactional tag on the service method. Hope that helps, Tony >> >> Chris >>
