-->
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.  [ 1 post ] 
Author Message
 Post subject: Exception when merging transient object
PostPosted: Thu Oct 09, 2008 9:14 am 
Newbie

Joined: Thu Oct 09, 2008 9:04 am
Posts: 1
Hi!

I´m having a problem when calling Session.merge() on a transient object whicha has an embeddable component, and that component also references the transient object via the @Parent annotation.

Apparently, the problem occurs when hibernate is trying to obtain the proxy for the transient object, which doesn´t exist because the object has just been attached to the session.

Here is the example code:

Code:
@Entity()
@Table(name="parent")
public class Parent {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private int id;

   @Embedded
   private Child child;

   
   public int getId() {
      return id;
   }


   public void setId(final int id) {
      this.id = id;
   }


   public Child getChild() {
      return child;
   }


   public void setChild(final Child child) {
      this.child = child;
   }

}


Code:
@Embeddable
public class Child {
   
   @Basic
   private int value;
   
   @org.hibernate.annotations.Parent
   private Parent parent;

   
   public int getValue() {
      return value;
   }

   public void setValue(final int value) {
      this.value = value;
   }

   public Parent getParent() {
      return parent;
   }

   public void setParent(final Parent parent) {
      this.parent = parent;
   }
}


Code:
public class Merge {


   public static void main(final String[] args) {
      final SessionFactory sessFactory = initSessionFactory();
      final Session session = sessFactory.openSession();

      final Parent parent = new Parent();
      final Child child = new Child();
      parent.setChild(child);
      child.setValue(1);
      child.setParent(parent);
      
      session.merge(parent);
   }

   
   private static SessionFactory initSessionFactory() {
      final MyHibnerateConfiguration cfg = new MyHibnerateConfiguration();



      final SessionFactory sessFactory = cfg.buildSessionFactory();

      return sessFactory;
   }

}


Here is the stacktrace of the exception:

Code:
Exception in thread "main" java.lang.NullPointerException
   at org.hibernate.engine.StatefulPersistenceContext.proxyFor(StatefulPersistenceContext.java:670)
   at org.hibernate.type.ComponentType.instantiate(ComponentType.java:492)
   at org.hibernate.type.ComponentType.replace(ComponentType.java:459)
   at org.hibernate.type.TypeFactory.replace(TypeFactory.java:515)
   at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:377)
   at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:179)
   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
   at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
   at ar.com.mindset.hibernate.Merge.main(Merge.java:18)


Any light on this issue will be appreciated...

Thanks!!


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

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.