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 !