Need help with Hibernate? Read this first:
Hello:
I have been tasked with pulling the data out of a staging database and saving it in XML.
For import into another database. The most convenient way to do this is via views,
because there are several complex joins to be handled and I feel more comfortable
doing this on the database side.
The problem is that there are no keys defined on views, therefore when
I use the tools, composite identifier classes get generated for the views.
Please see below.
My program reads an XML file which details whichs views to be run. So my
code does not know much about the views it is running. Therefore I need
to discover the attributes of the views at run time. For normal attributs
this is easy using ClassMetadata.getPropertyNames().
My problem is with the composite identifier. I can determine if there is an identifier
using ClassMetadata.getIdentifierPropertyName() and then use ClassMetadata.getIdentifier()
to get the identifier object. At this point how can I loop through the attributs on the
identifier object. Do I have to start using the bean classes?
Some clues would be very helpfull.
Many thanks
kd
package metadataexport;
// Generated by MyEclipse - Hibernate Tools
/**
* TemplateV generated by MyEclipse - Hibernate Tools
*/
public class TemplateV extends AbstractTemplateV implements java.io.Serializable {
// Constructors
/** default constructor */
public TemplateV() {
}
/** full constructor */
public TemplateV(TemplateVId id) {
super(id);
}
}
/**
* AbstractTemplateV generated by MyEclipse - Hibernate Tools
*/
public abstract class AbstractTemplateV implements java.io.Serializable {
// Fields
private TemplateVId id;
// Constructors
/** default constructor */
public AbstractTemplateV() {
}
/** full constructor */
public AbstractTemplateV(TemplateVId id) {
this.id = id;
}
// Property accessors
public TemplateVId getId() {
return this.id;
}
public void setId(TemplateVId id) {
this.id = id;
}
}
// Generated by MyEclipse - Hibernate Tools
import java.util.Date;
/**
* TemplateVId generated by MyEclipse - Hibernate Tools
*/
public class TemplateVId extends AbstractTemplateVId implements java.io.Serializable {
// Constructors
/** default constructor */
public TemplateVId() {
}
/** minimal constructor */
public TemplateVId(Integer templateKey, String templateNm, String versionNbr) {
super(templateKey, templateNm, versionNbr);
}
/** full constructor */
public TemplateVId(Integer templateKey, String templateNm, String templateDesc, Date modifiedDate, String versionNbr) {
super(templateKey, templateNm, templateDesc, modifiedDate, versionNbr);
}
}
import java.util.Date;
/**
* AbstractTemplateVId generated by MyEclipse - Hibernate Tools
*/
public abstract class AbstractTemplateVId implements java.io.Serializable {
// Fields
private Integer templateKey;
private String templateNm;
private String templateDesc;
private Date modifiedDate;
private String versionNbr;
// Constructors
/** default constructor */
public AbstractTemplateVId() {
}
/** minimal constructor */
public AbstractTemplateVId(Integer templateKey, String templateNm, String versionNbr) {
this.templateKey = templateKey;
this.templateNm = templateNm;
this.versionNbr = versionNbr;
}
/** full constructor */
public AbstractTemplateVId(Integer templateKey, String templateNm, String templateDesc, Date modifiedDate, String versionNbr) {
this.templateKey = templateKey;
this.templateNm = templateNm;
this.templateDesc = templateDesc;
this.modifiedDate = modifiedDate;
this.versionNbr = versionNbr;
}
// Property accessors
public Integer getTemplateKey() {
return this.templateKey;
}
public void setTemplateKey(Integer templateKey) {
this.templateKey = templateKey;
}
public String getTemplateNm() {
return this.templateNm;
}
public void setTemplateNm(String templateNm) {
this.templateNm = templateNm;
}
public String getTemplateDesc() {
return this.templateDesc;
}
public void setTemplateDesc(String templateDesc) {
this.templateDesc = templateDesc;
}
public Date getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
public String getVersionNbr() {
return this.versionNbr;
}
public void setVersionNbr(String versionNbr) {
this.versionNbr = versionNbr;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof AbstractTemplateVId) ) return false;
AbstractTemplateVId castOther = ( AbstractTemplateVId ) other;
return ( (this.getTemplateKey()==castOther.getTemplateKey()) || ( this.getTemplateKey()!=null && castOther.getTemplateKey()!=null && this.getTemplateKey().equals(castOther.getTemplateKey()) ) )
&& ( (this.getTemplateNm()==castOther.getTemplateNm()) || ( this.getTemplateNm()!=null && castOther.getTemplateNm()!=null && this.getTemplateNm().equals(castOther.getTemplateNm()) ) )
&& ( (this.getTemplateDesc()==castOther.getTemplateDesc()) || ( this.getTemplateDesc()!=null && castOther.getTemplateDesc()!=null && this.getTemplateDesc().equals(castOther.getTemplateDesc()) ) )
&& ( (this.getModifiedDate()==castOther.getModifiedDate()) || ( this.getModifiedDate()!=null && castOther.getModifiedDate()!=null && this.getModifiedDate().equals(castOther.getModifiedDate()) ) )
&& ( (this.getVersionNbr()==castOther.getVersionNbr()) || ( this.getVersionNbr()!=null && castOther.getVersionNbr()!=null && this.getVersionNbr().equals(castOther.getVersionNbr()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + ( getTemplateKey() == null ? 0 : this.getTemplateKey().hashCode() );
result = 37 * result + ( getTemplateNm() == null ? 0 : this.getTemplateNm().hashCode() );
result = 37 * result + ( getTemplateDesc() == null ? 0 : this.getTemplateDesc().hashCode() );
result = 37 * result + ( getModifiedDate() == null ? 0 : this.getModifiedDate().hashCode() );
result = 37 * result + ( getVersionNbr() == null ? 0 : this.getVersionNbr().hashCode() );
return result;
}
}
_________________ KBD
|