I'd like to be able to use a Java 5 Enum as a discrimitor value. Is this possible?
Eclipse gives me the following error at AddressType.MAXIMIZER.type():
The value for annotation attribute Inheritance.discriminatorValue must be
a constant expression
Hibernate version: 3.1-alpha1
Hibernate Annotations version: 3.1-beta3
EJB: ejb-3.0-edr
Annotated classes:
package com.dolby.pics.core.db.model.impl;
public enum AddressType {
MAPICS("MAPX"),
MAXIMIZER("MAXM"),
PEOPLESOFT_CRM("PCRM"),
PEOPLESOFT_FINANCE("PFIN");
AddressType(String type) {
this.type=type;
}
private String type;
public String type() { return this.type; }
}
/* Copyright 2005 Dolby Laboratories Inc. All rights reserved.
* See license distributed with this file or available at
*
http://ukdev/license.html
*/
package com.dolby.pics.core.db.model.impl;
import javax.persistence.AccessType;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* @hibernate.subclass discriminator-value="MAXM"
* @author djb
*/
@Entity(access=AccessType.FIELD)
@Inheritance(discriminatorValue=AddressType.MAXIMIZER.type())
public class MaximizerAddress extends Address
{
/**
*
*/
private static final long serialVersionUID = 3257006536231432248L;
@Basic
private Integer recordId;
/**
* @param originalAddressInfo
*/
public MaximizerAddress(OriginalAddressInfo originalAddressInfo)
{
this(originalAddressInfo, null);
}
/**
* @param originalAddressInfo
* @param recordId
*/
public MaximizerAddress(OriginalAddressInfo originalAddressInfo, Integer recordId)
{
super(originalAddressInfo);
setRecordId(recordId);
}
/**
* @return Returns the key.
*/
public Integer getRecordId()
{
return recordId;
}
/**
* @param key The key to set.
*/
public void setRecordId(final Integer recordId)
{
this.recordId = recordId;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
// do NOT use instanceof!
if (obj != null && getClass() == obj.getClass())
{
MaximizerAddress rhs = (MaximizerAddress) obj;
return new EqualsBuilder()
.append(getId(),rhs.getId())
.append(getRecordId(),rhs.getRecordId())
.isEquals();
}
return false;
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
return new HashCodeBuilder(17,37)
.append(getId())
.append(getRecordId())
.toHashCode();
}
/**
* @see com.dolby.pics.core.db.system.Entity#toString()
*/
@Override
public String toString()
{
return
getName()
+" [" //$NON-NLS-1$
+AddressType.MAXIMIZER
+"-" //$NON-NLS-1$
+getRecordId()
+"]"; //$NON-NLS-1$
}
}
Thanks,
daz