-->
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.  [ 2 posts ] 
Author Message
 Post subject: Embeddable gives PropertyAccessException on merge
PostPosted: Fri Aug 24, 2007 5:53 am 
Newbie

Joined: Tue Aug 08, 2006 7:48 am
Posts: 6
Hibernate version: 3.2.5.ga
Hibernate-annotations: 3.3.0.ga
Hibernate-entitymanager: 3.3.1.ga

MySQL 5.0.41

Hi!

I have a problem with embedding which I managed to cut down to a simple test case (I misused JUnit for it, could have also been a simple class with a main method).

In words: I have a Container with an optional 1:1-relation to a Containee which itself embedds an Embeddee. I first persist the container without a containee, detach it by closing and reopening the entity manager, then put a containee in the still detached container and eventually merge it back to the persistent context. There a PropertyAccessException is thrown. Source code is pretty simple. I left out package and import lines.

Is this a bug in hibernate or do we do something wrong?

Thanks!

Code:
public class EmbeddedTest extends TestCase {
   
   private EntityManagerFactory emf;
   private EntityManager em;
   private EntityTransaction tx;
   
   protected void setUp() throws Exception {
      super.setUp();
      
      emf = Persistence.createEntityManagerFactory("TEST_SE", map);
   }

   protected void tearDown() throws Exception {
   }

   public void testEmbedded() {
      em = emf.createEntityManager();

      tx = em.getTransaction();
      tx.begin();
      Container c = new Container();

      // persist container entity with no containee
      em.persist(c);

      tx.commit();
      
      int id = c.id;
      
      c = em.find(Container.class, id);

      // implicitely detach c by closing and reopening entitymanager
      em.close();
      em = emf.createEntityManager();

      // manipulate detached c
      c.containee = new Containee();
      
      tx = em.getTransaction();
      tx.begin();
      
      // merge c into persistent context
      Container cMerged = em.merge(c);
      
      /*
       * gives:
       *
       *javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.regiogmbh.inecos.framework.Embedee.string
       *
       **/

      tx.commit();

      em.close();
   }
}

@Entity
@AccessType("field")
@Table(
      name="container"
)
public class Container {

   @Id
   @GeneratedValue
   int id;

    @OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER,optional=true)
    Containee containee;

}

@Entity
@Table(
      name="containee"
)
public class Containee {
   
   @SuppressWarnings("unused")
   @Id
   @GeneratedValue
   int id;
   
   @Embedded
   Embedee embedee;

}

@Embeddable
@AccessType("field")
public class Embedee {
   
   String string = "string";

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 24, 2007 6:46 am 
Newbie

Joined: Tue Aug 08, 2006 7:48 am
Posts: 6
A reply to my own posting:

The code works with

hibernate 3.2.0.ga
hibernate-annotations 3.2.0.ga
hibernate-entitymanager 3.2.0.ga

And I forgot to post my 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="TEST_SE" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>Container</class>
    <class>Containee</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
      <property name="hibernate.max_fetch_depth" value="2" />
      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.use_sql_comments" value="true" />
      <property name="hibernate.hbm2ddl.auto" value="create-drop" />
      <property name="hibernate.ejb.autodetection" value="none" />
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test" />
      <property name="hibernate.connection.username" value="..." />
      <property name="hibernate.connection.password" value="..." />
      <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
      <property name="c3p0.acquire_increment" value="3" />
      <property name="c3p0.idle_test_period" value="300" />
      <property name="c3p0.initialPoolSize" value="10" />
      <property name="c3p0.min_size" value="15" />
      <property name="c3p0.max_size" value="50" />
      <property name="c3p0.timeout" value="1800" />
      <!--  -->
      <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
    </properties>
  </persistence-unit>
</persistence>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.