我正在从 DOS 运行 DataNucleus 增强器,如下所示:
java -cp C:\Users\Chania\workspace\myproject\war\WEB-INF\classes\;C:\repo\datanucleus-full-3.1.0-release\lib\datanucleus-enhancer-3.1.0-release.jar;C:\repo\datanucleus-full-3.1.0-release\lib\datanucleus-core-3.1.0-release.jar;C:\repo\datanucleus-full-3.1.0-release\deps\jdo-api-3.1-SNAPSHOT-20110926.jar;C:\repo\datanucleus-full-3.1.0-release\lib\datanucleus-api-jdo-3.1.0-release.jar;C:\repo\datanucleus-full-3.1.0-release\deps\log4j-1.2.14.jar;C:\repo\datanucleus-full-3.1.0-release\deps\asm-4.0.jar -Dlog4j.configuration=file:C:\repo\datanucleus-full-3.1.0-release\log4j.properties org.datanucleus.enhancer.DataNucleusEnhancer -v C:\Users\Chania\workspace\myproject\war\WEB-INF\classes\com\myproject\domain\*.class > logfile.txt
我使用的 Java 版本是:
java version "1.6.0_27"
我得到的错误如下:
...
308 [main] DEBUG DataNucleus.Persistence - Added converter for java.net.URI<->java.lang.String using org.datanucleus.store.types.converters.URIStringConverter
308 [main] DEBUG DataNucleus.Persistence - Added converter for java.net.URL<->java.lang.String using org.datanucleus.store.types.converters.URLStringConverter
309 [main] DEBUG DataNucleus.Persistence - Added converter for java.util.UUID<->java.lang.String using org.datanucleus.store.types.converters.UUIDStringConverter
309 [main] DEBUG DataNucleus.Persistence - TypeConverter for javax.time.calendar.LocalDate<->java.lang.String ignored since java type not present in CLASSPATH
310 [main] DEBUG DataNucleus.Persistence - TypeConverter for javax.time.calendar.LocalTime<->java.lang.String ignored since java type not present in CLASSPATH
311 [main] DEBUG DataNucleus.Persistence - TypeConverter for javax.time.calendar.LocalTime<->java.lang.Long ignored since java type not present in CLASSPATH
312 [main] DEBUG DataNucleus.Persistence - TypeConverter for javax.time.calendar.LocalDateTime<->java.lang.String ignored since java type not present in CLASSPATH
312 [main] DEBUG DataNucleus.Persistence - Type converter support loaded
312 [main] DEBUG DataNucleus.MetaData - MetaDataManager : Input=(XML,Annotations), XML-Validation=false, XML-Suffices=(persistence=*.jdo, orm=orm, query=*.jdoquery), JDO-listener=false
338 [main] DEBUG DataNucleus.MetaData - MetaData Management : Loading Metadata for classes "[com.myproject.domain.Record, com.myproject.domain.RecordSummary, com.myproject.domain.Comment]" ...
411 [main] DEBUG DataNucleus.MetaData - Class "com.myproject.domain.Record" has been specified with JDO annotations so using those.
596 [main] DEBUG DataNucleus.MetaData - Class "com.myproject.domain.RecordSummary" has been specified with JDO annotations so using those.
600 [main] DEBUG DataNucleus.MetaData - Class "com.myproject.domain.Comment" has been specified with JDO annotations so using those.
Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
604 [main] ERROR DataNucleus.Enhancer - DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors
Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
org.datanucleus.exceptions.NucleusUserException: Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:536)
at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
Caused by: java.lang.NullPointerException
at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
... 3 more
Nested Throwables StackTrace:
java.lang.NullPointerException
at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors
增强类的来源如下:
@PersistenceCapable(detachable = "true")
public class Record implements Serializable, Cacheable<String> {
private static final long serialVersionUID = 9022509306966814904L;
@PrimaryKey
@Persistent(defaultFetchGroup = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
private String id;
@Name
@Persistent(defaultFetchGroup = "true")
private String name;
@Name
@Persistent(defaultFetchGroup = "true")
private String surname;
@Persistent(defaultFetchGroup = "true")
private Date dateOfBirth;
@Persistent(defaultFetchGroup = "true")
private Date dateRecorded;
@Persistent(defaultFetchGroup = "true")
private String locationId;
@Persistent(embedded = "true", defaultFetchGroup = "true")
private CustomLocation customLocation;
@Persistent(defaultFetchGroup = "true")
private Category category;
@Persistent(embedded = "true", defaultFetchGroup = "true")
private CustomCategory customCategory;
@Persistent(defaultFetchGroup = "true")
private String description;
@Persistent(embeddedElement = "true", defaultFetchGroup = "true")
private List<StoredImageInfo> images;
@Persistent(embeddedElement = "true", defaultFetchGroup = "true")
private List<StoredAudioInfo> audio;
@Persistent(embeddedElement = "true", defaultFetchGroup = "true")
private List<StoredFileInfo> files;
@Persistent(defaultFetchGroup = "true")
private ModerationMode moderationMode;
@Persistent(defaultFetchGroup = "true")
private VisibilityMode visibilityMode;
@Persistent(embedded = "true", defaultFetchGroup = "true")
private UserProfileSummary owner;
@Persistent(embeddedElement = "true", defaultFetchGroup = "true")
private Map<String, UserProfileSummary> editors;
@Persistent(embeddedElement = "true", defaultFetchGroup = "true")
private Map<String, UserProfileSummary> connections;
@Persistent(embeddedElement = "true", defaultFetchGroup = "true")
private Map<String, RecordSummary> recordConnections;
@Persistent(defaultFetchGroup = "true")
private RecordType type;
@Persistent(defaultFetchGroup = "true")
private Date expiry;
public Record() {
}
public Record(Record copy) {
deepCopy(copy);
}
...
}
@PersistenceCapable(embeddedOnly = "true")
public class RecordSummary implements Serializable {
private static final long serialVersionUID = 9024309306966814904L;
@Persistent(defaultFetchGroup = "true")
private String id;
@Persistent(defaultFetchGroup = "true")
private RecordRole role;
@Persistent(defaultFetchGroup = "true")
private String name;
@Persistent(defaultFetchGroup = "true")
private String surname;
@Persistent(defaultFetchGroup = "true")
private Date dateOfBirth;
@Persistent(defaultFetchGroup = "true")
private Date dateRecorded;
@SuppressWarnings("unused")
private RecordSummary() {
// for serialization
}
...
}
@PersistenceCapable(detachable = "true")
public class Comment implements Attachable<String>, Serializable {
private static final long serialVersionUID = -7624377549524333808L;
@PrimaryKey
@Persistent(defaultFetchGroup = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
private String id;
@Persistent(defaultFetchGroup = "true")
private String recordId;
@Persistent(defaultFetchGroup = "true")
private String username;
@Persistent(defaultFetchGroup = "true")
private Date date;
@Persistent(defaultFetchGroup = "true")
private String content;
@SuppressWarnings("unused")
private Comment() {
// for serialization
}
...
}
使用 datanucleus 增强器 3.0-release 时,我没有遇到任何此类异常(尽管 3.0 存在其他问题:问题 1,问题 2)。 这是 DataNucleus 3.1 的错误还是我做错了什么?
更新:DataNucleus EnhancerNullPointerException
为所有标有@Persistent(embeddedElement = "true")
. 这很可能是 DataNucleus 3.1 Enhancer 的错误。
更新 2:根据要求,我包含重现问题的最少代码:
@PersistenceCapable(detachable = "true")
public class Record {
@PrimaryKey
@Persistent(defaultFetchGroup = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
private String id;
@Persistent(embeddedElement = "true", defaultFetchGroup = "true")
private List<MyEmbeddedElement> aList;
public Record() {
}
}
@PersistenceCapable(embeddedOnly = "true")
public class MyEmbeddedElement {
@Persistent
private String myField;
}
错误:
730 [main] DEBUG DataNucleus.MetaData - Class "com.myproject.domain.Record" has been specified with JDO annotations so using those.
760 [main] DEBUG DataNucleus.MetaData - Class "com.myproject.domain.MyEmbeddedElement" has been specified with JDO annotations so using those.
Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
763 [main] ERROR DataNucleus.Enhancer - DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors
Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
org.datanucleus.exceptions.NucleusUserException: Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:536)
at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
Caused by: java.lang.NullPointerException
at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
... 3 more
Nested Throwables StackTrace:
java.lang.NullPointerException
at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors
更新 3:从 3.0.2 开始的所有 DataNucleus 版本中都存在此问题。