-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using an Enum for a discriminator value annotation
PostPosted: Sun Jul 10, 2005 10:20 am 
Beginner
Beginner

Joined: Sun Jun 13, 2004 9:49 pm
Posts: 38
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
EnhancedUserType


Top
 Profile  
 
 Post subject: Is there no way to use an enum?
PostPosted: Sun Jul 10, 2005 5:08 pm 
Beginner
Beginner

Joined: Sun Jun 13, 2004 9:49 pm
Posts: 38
This seems such a logical way to go. Will this be supported in the EJB spec anytime?

I've seen other enums used in this way in annotations, but when i try it i keep getting the eclipse error. Am doing something wrong?

thanks

daz


Top
 Profile  
 
 Post subject: Re: Is there no way to use an enum?
PostPosted: Thu Aug 11, 2005 8:19 am 
Newbie

Joined: Thu Aug 11, 2005 7:27 am
Posts: 1
Kango wrote:
This seems such a logical way to go. Will this be supported in the EJB spec anytime?

I've seen other enums used in this way in annotations, but when i try it i keep getting the eclipse error. Am doing something wrong?

thanks

daz


Discriminator values must be compile-time-constants.
Therefore return values from methods are not allowed (same as case-constants in switch-statement).
But you can use the enum type itself.


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