-->
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: XML deserialization of child properies in Ann. 3.3.0.GA
PostPosted: Thu May 03, 2007 7:37 am 
Newbie

Joined: Mon Apr 23, 2007 7:29 am
Posts: 4
Location: Berlin (Germany)
First congratulation to the annotations team for that product !
I've read the changelog of ann. 3.3.0
http://opensource.atlassian.com/project ... se/ANN-531
with a great concern, because now it's possible to deserialize child properties with annotations. I tried to generate XML, but like described before only the Ids of the child objects were deserialized, not all properties.

Hibernate version: 3.2.3
Annotations version: 3.3.0.GA

Mapping documents:

Code:
@Entity
@Table(name = "parent_test")
@SequenceGenerator(name = "SEQ_STORE", sequenceName = "parent_test_seq", allocationSize = 1)

public class ParentTest {
      
   private Long Id;   
   private String parentAttribute1;
   private Set<ChildTest> ChildTests;   
   
   @Id
   @Column(name = "parent_test_id")
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
   public Long getId() {
      return Id;
   }

   public void setId(Long id) {
      Id = id;
   }
   
   @Column (name = "parent_attribute1")
   public String getParentAttribute1() {
      return parentAttribute1;
   }

   public void setParentAttribute1(String parentAttribute1) {
      this.parentAttribute1 = parentAttribute1;
   }
   
   @OneToMany(cascade = CascadeType.ALL)
   @JoinColumn(name = "parent_test_id")
   @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   public Set<ChildTest> getChildTests() {
      return ChildTests;
   }   
   
   public void setChildTests(Set<ChildTest> childTests) {
      ChildTests = childTests;
   }
      
}


Code:
@Entity
@Table(name = "child_test")
@SequenceGenerator(name = "SEQ_STORE", sequenceName = "child_test_seq", allocationSize = 1)

public class ChildTest {
   
   private Long Id;   
   private String childAttribute1;
   
   @Id
   @Column(name = "child_test_id")
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
   public Long getId() {
      return Id;
   }

   public void setId(Long id) {
      Id = id;
   }
   
   @Column (name = "child_attribute1")
   public String getChildAttribute1() {
      return childAttribute1;
   }

   public void setChildAttribute1(String childAttribute1) {
      this.childAttribute1 = childAttribute1;
   }   
   
}



Code between sessionFactory.openSession() and session.close():
Code:
Session dom4jSession = sf.getCurrentSession().getSession(
            EntityMode.DOM4J);
      Session pojoSession = sf.getCurrentSession();
      
      ChildTest  childTest1 = new ChildTest();
      childTest1.setChildAttribute1("childAttribute1");
      ChildTest  childTest2 = new ChildTest();
      childTest2.setChildAttribute1("childAttribute1");
      ChildTest  childTest3 = new ChildTest();
      childTest3.setChildAttribute1("childAttribute1");
      
      Set<ChildTest> childTests = new HashSet<ChildTest>();
      childTests.add(childTest1);
      childTests.add(childTest2);
      childTests.add(childTest3);
      
      ParentTest parentTest = new ParentTest();
      parentTest.setParentAttribute1("ParentAttribute1");
      parentTest.setChildTests(childTests);
      
      pojoSession.save(parentTest);
      pojoSession.flush();
      
      Document doc = DocumentFactory.getInstance().createDocument();
      
      Element result = (Element) dom4jSession.createQuery("from ParentTest").uniqueResult();
      
      
      doc.add(result);

      ByteArrayOutputStream os = new ByteArrayOutputStream();
      OutputFormat format = new OutputFormat();
      format.setEncoding("ISO-8859-1");
      XMLWriter writer = new XMLWriter(os, format);
      writer.write(doc);
      writer.close();


Generated XML:

<ParentTest><id>4</id>
<childTests>
<ChildTest>10</ChildTest>
<ChildTest>11</ChildTest>
<ChildTest>12</ChildTest>
</childTests>
<parentAttribute1>ParentAttribute1</parentAttribute1>
</ParentTest>

Name and version of the database you are using:
postgresql-8.1

I tried to set the Annotations outside the getters like described in http://opensource.atlassian.com/project ... se/ANN-531 and also outside the definition of the properties. In every case I get the same result.

Can anybody reproduce that behaviour of ann. 3.3.0 ? Did I forgot anything ?

Thanks in advance !


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 9:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://opensource.atlassian.com/projects/hibernate/browse/ANN-572
has to be implemented before using the XML mode with annotations

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 1:22 am 
Newbie

Joined: Mon Apr 23, 2007 7:29 am
Posts: 4
Location: Berlin (Germany)
In http://opensource.atlassian.com/project ... se/ANN-531 I found the description:
The XML deserialization of an entity does not deserializes its child properties but only its id
(quite the same problem than my)

Example:

Generated XML (the age property of Foobean is missing, i.e there is no <name>foo</name><age>age</age>) :

<Screen>
<id>1</id>
<foobeans>
<Foobean>foo</Foobean>
</foobeans>
</Screen>

Status of http://opensource.atlassian.com/project ... se/ANN-531 is 'resolved' (fixed in 3.3.0.GA) .
That means that this problem is fixed in Annotations 3.3.0.GA, isn't it ?
Does the @node annotation has to be implemented before the deserialization of child properties works ? If yes, why that problem has the status 'resolved' ?

Of cause, the @node annotation would be a 'full' fix, as I read already.

Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 9:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
As explained in the case, I asked for feedback and it never came.
So I have opened ANN-572

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 6:19 am 
Newbie

Joined: Mon Apr 23, 2007 7:29 am
Posts: 4
Location: Berlin (Germany)
In result, deserialization of child properties does not work with Annotations 3.3.0 GA , unfortunately. But I'm surprised about the status 'resolved' of that case.


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.