-->
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.  [ 3 posts ] 
Author Message
 Post subject: base mapping class
PostPosted: Fri Jan 30, 2004 6:15 am 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
I was trying to use the Persistent base class pattern.

I am using xdoclet tags to generate my hbm files.

All I get is "<XDocletMain.start 54 ) <<Class com.axium.poc.ContactInfo misses ID property>>" however...

I want it to use the ID from the Persistent base class. What am I doing wrong?




----------

package com.poc.base;

import net.sf.hibernate.*;

import java.io.Serializable;
import java.sql.SQLException;

/**
* @hibernate.class
*/

public abstract class Persistent implements Serializable {

protected Long _id;
protected int _version;

/**
* @hibernate.id
* column="id"
* generator-class="assigned"
*/
public Long getIdentifier() {
return _id;
}

public void setIdentifier(Long id) {
_id = id;
}

public int getVersion() {
return _version;
}

public void setVersion(int version) {
_version = version;
}


}

and

/*
* This class was automatically generated with
* <a href="http://www.castor.org">Castor 0.9.5.2</a>, using an XML
* Schema.
* $Id$
*/

package com.poc;

//---------------------------------/
//- Imported classes and packages -/
//---------------------------------/

import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.io.Writer;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.ContentHandler;

/**
* Class ContactInfo.
*
* @version $Revision$ $Date$
* @hibernate.class
* table="ContactInfo"
*/
public class ContactInfo extends ContactInfoType
implements java.io.Serializable
{


//----------------/
//- Constructors -/
//----------------/

public ContactInfo() {
super();
} //-- com.poc.ContactInfo()


//-----------/
//- Methods -/
//-----------/

/**
* Note: hashCode() has not been overriden
*
* @param obj
*/
public boolean equals(java.lang.Object obj)
{
if ( this == obj )
return true;

if (super.equals(obj)==false)
return false;

if (obj instanceof ContactInfo) {

ContactInfo temp = (ContactInfo)obj;
return true;
}
return false;
} //-- boolean equals(java.lang.Object)

/**
* Method isValid
*/
public boolean isValid()
{
try {
validate();
}
catch (org.exolab.castor.xml.ValidationException vex) {
return false;
}
return true;
} //-- boolean isValid()

/**
* Method marshal
*
* @param out
*/
public void marshal(java.io.Writer out)
throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
{

Marshaller.marshal(this, out);
} //-- void marshal(java.io.Writer)

/**
* Method marshal
*
* @param handler
*/
public void marshal(org.xml.sax.ContentHandler handler)
throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
{

Marshaller.marshal(this, handler);
} //-- void marshal(org.xml.sax.ContentHandler)

/**
* Method unmarshal
*
* @param reader
*/
public static java.lang.Object unmarshal(java.io.Reader reader)
throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
{
return (com.poc.ContactInfo) Unmarshaller.unmarshal(com.poc.ContactInfo.class, reader);
} //-- java.lang.Object unmarshal(java.io.Reader)

/**
* Method validate
*/
public void validate()
throws org.exolab.castor.xml.ValidationException
{
org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
validator.validate(this);
} //-- void validate()

}



and


/*
* This class was automatically generated with
* <a href="http://www.castor.org">Castor 0.9.5.2</a>, using an XML
* Schema.
* $Id$
*/

package com.poc;

//---------------------------------/
//- Imported classes and packages -/
//---------------------------------/

import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.io.Writer;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.ContentHandler;

/**
* Class ContactInfoType.
*
* @version $Revision$ $Date$
* @hibernate.subclass
* table="ContactInfo"
*/
public class ContactInfoType extends com.poc.base.Persistent
implements java.io.Serializable
{


//--------------------------/
//- Class/Member Variables -/
//--------------------------/

/**
* Field personName
*/
private com.poc.PersonName personName;

/**
* Field contactMethod
*/
private com.poc.ContactMethod contactMethod;


//----------------/
//- Constructors -/
//----------------/

public ContactInfoType() {
super();
} //-- com.poc.ContactInfoType()


//-----------/
//- Methods -/
//-----------/

/**
* Note: hashCode() has not been overriden
*
* @param obj
*/
public boolean equals(java.lang.Object obj)
{
if ( this == obj )
return true;

if (super.equals(obj)==false)
return false;

if (obj instanceof ContactInfoType) {

ContactInfoType temp = (ContactInfoType)obj;
if (this.personName != null) {
if (temp.personName == null) return false;
else if (!(this.personName.equals(temp.personName)))
return false;
}
else if (temp.personName != null)
return false;
if (this.contactMethod != null) {
if (temp.contactMethod == null) return false;
else if (!(this.contactMethod.equals(temp.contactMethod)))
return false;
}
else if (temp.contactMethod != null)
return false;
return true;
}
return false;
} //-- boolean equals(java.lang.Object)

/**
* Method getContactMethod
*
* @hibernate.property
* column="contactMethod"
*/
public com.poc.ContactMethod getContactMethod()
{
return this.contactMethod;
} //-- com.poc.ContactMethod getContactMethod()

/**
* Method getPersonName
*
* @hibernate.property
* column="personName"
*/
public com.poc.PersonName getPersonName()
{
return this.personName;
} //-- com.poc.PersonName getPersonName()

/**
* Method isValid
*/
public boolean isValid()
{
try {
validate();
}
catch (org.exolab.castor.xml.ValidationException vex) {
return false;
}
return true;
} //-- boolean isValid()

/**
* Method marshal
*
* @param out
*/
public void marshal(java.io.Writer out)
throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
{

Marshaller.marshal(this, out);
} //-- void marshal(java.io.Writer)

/**
* Method marshal
*
* @param handler
*/
public void marshal(org.xml.sax.ContentHandler handler)
throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
{

Marshaller.marshal(this, handler);
} //-- void marshal(org.xml.sax.ContentHandler)

/**
* Sets the value of field 'contactMethod'.
*
* @param contactMethod the value of field 'contactMethod'.
*/
public void setContactMethod(com.poc.ContactMethod contactMethod)
{
this.contactMethod = contactMethod;
} //-- void setContactMethod(com.poc.ContactMethod)

/**
* Sets the value of field 'personName'.
*
* @param personName the value of field 'personName'.
*/
public void setPersonName(com.poc.PersonName personName)
{
this.personName = personName;
} //-- void setPersonName(com.poc.PersonName)

/**
* Method unmarshal
*
* @param reader
*/
public static java.lang.Object unmarshal(java.io.Reader reader)
throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
{
return (com.poc.ContactInfoType) Unmarshaller.unmarshal(com.poc.ContactInfoType.class, reader);
} //-- java.lang.Object unmarshal(java.io.Reader)

/**
* Method validate
*/
public void validate()
throws org.exolab.castor.xml.ValidationException
{
org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
validator.validate(this);
} //-- void validate()

}


Top
 Profile  
 
 Post subject: id tag
PostPosted: Fri Jan 30, 2004 5:00 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
I assume I have to specify some id tag in the child class.. but I am unsure how to do this.

I am sure this is something simple.. appreciate your assistance.


Is there more documentation on how to use the 'Persistent' base class. The one I found had the class code but not really much else.

In the case above...

Would you also implement a method 'getContactInfoId()' which calls the 'getIdentity()' from the base case?

Just not sure how to take advantage of this base Persistent class properly.

There obviously has to be some way to tell hibernate which database field the 'ID' attribute maps to.

i.e. ContactInfo --> ID (getIdentity) is contactInfoId
Foo -> ID (getIdentity) is FooId
etc

Can someone clear this up a bit for me?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 7:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I do base class property inheritance wo any pb.

_________________
Emmanuel


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