Note that this issue is separate/orthogonal from the
InheritenceType.TABLE_PER_CLASS issue I posted on earlier.
I am trying to implement JPA persistence in the implementation of an ISO
standard where I cannot change the relational schema at the bottom and
the XMl Schema at the top of the stack. The XML Schema is mapped to Java
classes using JAXB2 data binding. The persistence layer needs to use JPA
and Entity classes to persist JAXB2 binding classes into the relational
database. I am having trouble with one aspect of the mapping and need
some advice.
*Overview*
-In Object model, a RegistryObject has a collection of Property instances
-In Object model, a Property instance has a collection of String values
(for multi-valued properties)
-In relational schema, a RegistryObject is mapped to a row in the
RegistryObject table
-In relational schema, a multi-valued Property is mapped to multiple
rows of a Property table where each row provides a single value for a
logical Property
-Somehow, the JPA layer needs to map multple rows of Property table to a
single PropertyType (this is the problem).
*JAXB Binding Classes*
The suffix "Type" is added by JAXB and makes it clear that the class is
a JAXB binding class.
public class RegistryObjectType {
protected List<PropertyType> slot;
...
}
public class PropertyType {
protected ValueListType valueList;
protected String name;
...
}
public class ValueListType {
@XmlElement(name = "Value")
protected List<String> value;
...
}
*Relational Schema*
In the relational schema a Property instance is mapped to multiple rows
of Property table where each row provides one value in the valueList of
PropertyType. So Several rows of PropertyTable map to a single
PropertyType and a RegistryObject has a Collection<PropertyType>.
CREATE TABLE RegistryObject (
id VARCHAR(256) NOT NULL PRIMARY KEY
...
);
CREATE TABLE Property (
--The sequenceid is to keep the collection of values ordered
sequenceId INT NOT NULL,
name_ VARCHAR(256) NOT NULL,
value VARCHAR(256),
--The parent RegistryObject that this is a Property for
parent VARCHAR(256) NOT NULL,
PRIMARY KEY (parent, name_, sequenceId)
);
*JPA Entity Classes*
These are modified versions of classes generated by NetBeans 5.5
wizard that generated them from the relational schema.
@Entity
public class RegistryObject implements Serializable {
@Id
@Column(name = "ID", nullable = false)
protected String id;
@OneToMany (mappedBy="parent", cascade={CascadeType.REMOVE,
CascadeType.PERSIST})
private Collection<Property> properties;
...
}
@Entity
@Table(name = "Property")
public class Property implements Serializable {
@EmbeddedId
protected PropertyPK propertyPK;
@Column(name = "VALUE")
private String value;
...
}
@Embeddable
public class PropertyPK implements Serializable {
@Column(name = "SEQUENCEID", nullable = false)
private int sequenceid;
@Column(name = "NAME_", nullable = false)
private String name;
@ManyToOne
@JoinColumn(name = "parent", referencedColumnName = "id", nullable =
false)
private RegistryObject parent;
}
I am at a loss as to how to model the Entity classes so that they match
the desired model of the JAXB Binding classes. Thanks for any advice on
this.
--
Regards,
Farrukh
Web: http://www.wellfleetsoftware.com