我正在使用继承的MySQL dB架构,我无法改变。我正在尝试使用DataNucleus(JDO)。
我在架构中有以下内容:
CREATE TABLE `vendors` (
`vendor_id` INT(11) NOT NULL AUTO_INCREMENT,
...
`registration_method` ENUM('Company','Basic Upgrade','Website','Secure Admin','Unknown') NULL DEFAULT NULL,
...
PRIMARY KEY (`vendor_id`),
...
我已经定义了一个POJO来处理它:
@PersistenceCapable( table="vendors" )
public class VendorRec {
...
public static enum registration_method_enum {
Company( "Company" ), Basic_Upgrade( "Basic Upgrade" ), Website( "Website" ), Secure_Admin( "Secure Admin" ), Unknown( "Unknown" );
private String registration_method;
registration_method_enum( String registration_method ) {
this.registration_method = registration_method;
}
public String getRegistration_method() {
return this.registration_method;
}
};
...
@PrimaryKey
private Integer vendor_id;
...
private registration_method_enum registration_method;
...
我正在使用DataNucleus的JDO接口来检索此类:
Set<Integer> vendorIds = new HashSet();
...
Query q = persistenceManager.newQuery( VendorRec.class );
q.declareParameters( "java.util.Set vendorIds" );
q.setFilter( "vendorIds.contains( vendor_id )" );
q.setOrdering("vendor_fname ascending, vendor_lname ascending");
final Iterator<VendorRec> vendorIt = ( ( List<VendorRec> )q.execute( vendorIds ) ).iterator();
我得到以下异常:
java.lang.IllegalArgumentException: No enum constant ca.vendorlink.app.schema.VendorRec.registration_method_enum.Secure Admin
...
好吧,呃!当然,没有枚举常数&#34; registration_method_enum.Secure Admin&#34;!不允许有空位!但那是我继承的dB定义...: - (
解决此问题的建议?我应该以不同的方式定义枚举吗?
非常感谢提前。