我们正在将所有第三方库升级到最新版本,主要与Spring 4和Hibernate 4相关。修复所有编译问题后,我遇到了Jboss 4.2.3中的部署问题。当我调试Hibernate代码时,我想出了异常的位置。但不确定为什么会导致NPE。
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheService' defined in class path resource [dataSource.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [dataSource.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 152 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [dataSource.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 162 more
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:550)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:258)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1596)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1519)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1420)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416)
at com.om.dh.util.EnhancedAnnotationSessionFactoryBean.afterPropertiesSet(EnhancedAnnotationSessionFactoryBean.java:185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 169 more
当referenceEntity.getKey()为org.hibernate.cfg.Ejb3JoinColumn.java中的以下对象返回null时,会发生异常。这适用于Hibernate 3.3.0和Spring 3.2.2
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "lk_mc_instrument_type")
public class MCInstrumentType {
@Id
@OneToOne(mappedBy = "instrumentType" )
@JoinColumn(name="mc_instrument_type_code" )
private String code;
private String description;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String toString(){
return description;
}
}
上面的类是从以下域对象引用的。
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import com.domainlanguage.time.CalendarDate;
import com.om.dh.domain.AuditInfo;
import com.om.dh.util.idgenerator.DatabaseIdGenerator;
@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "mc_early_close_instrument")
@GenericGenerator(name="EarlyCloseInstrument_gen",strategy="com.om.dh.util.idgenerator.DatabaseIdGenerator",
parameters={@Parameter(name=DatabaseIdGenerator.INITIAL_PARAM,value="1"),
@Parameter(name = DatabaseIdGenerator.INCREMENT_PARAM, value = "50")})
public class EarlyCloseInstrument {
@Id
@Column(name="EARLY_CLOSE_INST_ID")
@GeneratedValue(generator="EarlyCloseInstrument_gen")
private Long earlycloseInstrumentId;
@OneToOne()
@JoinColumn (name = "INSTRUMENT_TYPE_CODE", referencedColumnName = "mc_instrument_type_code", updatable = false, insertable = false)
private MCInstrumentType instrumentType;
@Column(name="DATE")
@Type(type = "com.om.dh.util.CalendarUserType")
private CalendarDate date;
@Column(name="END_TIME")
private Date time;
@Embedded
private AuditInfo auditInfo;
@Version
@Column(name="VERSION_NUMBER")
private Integer versionNumber;
@Column(name="END_TIMEZONE")
private String endTimezone;
public String getEndTimezone() {
return endTimezone;
}
public void setEndTimezone(String endTimezone) {
this.endTimezone = endTimezone;
}
public AuditInfo getAuditInfo() {
return auditInfo;
}
public void setAuditInfo(AuditInfo auditInfo) {
this.auditInfo = auditInfo;
}
public Integer getVersionNumber() {
return versionNumber;
}
public void setVersionNumber(Integer versionNumber) {
this.versionNumber = versionNumber;
}
public CalendarDate getDate() {
return date;
}
public void setDate(CalendarDate date) {
this.date = date;
}
public Long getEarlycloseInstrumentId() {
return earlycloseInstrumentId;
}
public void setEarlycloseInstrumentId(Long earlycloseInstrumentId) {
this.earlycloseInstrumentId = earlycloseInstrumentId;
}
public MCInstrumentType getInstrumentType() {
return instrumentType;
}
public void setInstrumentType(MCInstrumentType instrumentType) {
this.instrumentType = instrumentType;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
}
我列出了war文件下WEB-INF / lib文件夹中的jar。
activation-1.1.jar
activemq-core-5.7.0.jar
activemq-pool-5.7.0.jar
activemq-protobuf-1.1.jar
ant-1.5.jar
antlr-2.7.7.jar
aopalliance-1.0.jar
apache-mime4j-core-0.7.2.jar
appia-6.1.8.1.jar
asm-3.3.1.jar
asm-commons-3.3.1.jar
asm-tree-3.3.1.jar
aspectjrt-1.7.4.jar
aspectjweaver-1.7.4.jar
avalon-framework-api-4.3.1.jar
avalon-framework-impl-4.3.1.jar
axiom-api-1.2.14.jar
axiom-impl-1.2.14.jar
axis2-1.3.jar
axis-c8-1.0.jar
backport-util-concurrent-3.1.jar
batch-core-7.0-SNAPSHOT.jar
batik-awt-util-1.6-1.jar
batik-bridge-1.6-1.jar
batik-css-1.6-1.jar
batik-dom-1.6-1.jar
batik-ext-1.6-1.jar
batik-extension-1.6-1.jar
batik-gui-util-1.6-1.jar
batik-gvt-1.6-1.jar
batik-parser-1.6-1.jar
batik-script-1.6-1.jar
batik-svg-dom-1.6-1.jar
batik-transcoder-1.6-1.jar
batik-util-1.6-1.jar
batik-xml-1.6-1.jar
bcmail-jdk14-138.jar
bcprov-jdk14-138.jar
blazeds-common-3.2.0.3978.jar
blazeds-core-3.2.0.3978.jar
blazeds-proxy-3.2.0.3978.jar
blazeds-remoting-3.2.0.3978.jar
Cairngorm.swc
castor-1.1.2.1.jar
cglib-nodep-2.1_3.jar
com.ibm.jbatch-tck-spi-1.0.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-dbcp-1.2.2.jar
commons-digester-1.8.jar
commons-discovery-0.4.jar
commons-fileupload-1.1.1.jar
commons-httpclient-3.0.1.jar
commons-io-1.4.jar
commons-jexl-1.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
commons-math-1.1.jar
commons-net-1.4.1.jar
commons-pool-1.6.jar
commons-vfs-1.0.jar
corelib.swc
custompopupmanager.swc
cxf-api-2.7.9.jar
cxf-rt-bindings-soap-2.7.9.jar
cxf-rt-bindings-xml-2.7.9.jar
cxf-rt-core-2.7.9.jar
cxf-rt-databinding-jaxb-2.7.9.jar
cxf-rt-frontend-jaxws-2.7.9.jar
cxf-rt-frontend-simple-2.7.9.jar
cxf-rt-transports-http-2.7.9.jar
cxf-rt-ws-addr-2.7.9.jar
cxf-rt-ws-policy-2.7.9.jar
dom4j-1.6.1.jar
domain-7.0-SNAPSHOT.jar
encoder-1.1.1.jar
extra166y-1.0.jar
FastInfoset-1.2.12.jar
fix-4.4-appia-6.1.8.1.jar
flexhttpplugin.swc
flexjsonplugin.swc
fontbox-1.8.4.jar
fop-0.94.jar
freemarker-2.3.19.jar
geronimo-j2ee-management_1.0_spec-1.1.jar
geronimo-jms_1.1_spec-1.1.1.jar
geronimo-jta_1.0.1B_spec-1.0.1.jar
hawtbuf-1.9.jar
hawtdispatch-1.11.jar
hawtdispatch-transport-1.11.jar
hibernate-commons-annotations-4.0.4.Final.jar
hibernate-core-4.3.2.Final.jar
hibernate-jmx-3.5.6-Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-validator-4.3.2.Final.jar
icu4j-4.0.1.jar
istack-commons-runtime-2.16.jar
itext-2.1.4.jar
jackson-core-asl-1.0.0.jar
jandex-1.1.0.Final.jar
janino-2.5.15.jar
jasypt-1.9.2.jar
jasypt-hibernate4-1.9.2.jar
jasypt-spring31-1.9.2.jar
jasypt-springsecurity3-1.9.2.jar
javassist-3.18.1-GA.jar
javax.batch-api-1.0.jar
jaxb-core-2.2.7.jar
jaxb-impl-2.2.7.jar
jaxen-1.1.4.jar
jaxrpc-api-1.1.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
jempbox-1.8.4.jar
jettison-1.2.jar
jmxri-1.2.1.jar
jmxtools-1.2.1.jar
joda-time-2.3.jar
js-1.5R4.1.jar
jsch-0.1.38.jar
json.swc
jsr166y-1.0.jar
jxls-core-0.9.5.jar
kahadb-5.7.0.jar
Lightstreamer_as_client.swc
log4j-1.2.15.jar
log4j-extras-1.1.jar
lucene-core-3.6.0.jar
mail-1.4.jar
mina-core-1.1.7.jar
mina-filter-ssl-1.1.7.jar
mina-integration-spring-1.1.7.jar
mqtt-client-1.3.jar
neethi-3.0.3.jar
ognl-3.0.6.jar
opencsv-1.8.jar
openfast-core-1.1.2.jar
oro-2.0.8.jar
pdfbox-1.8.4.jar
poi-3.0.1-FINAL.jar
quartz-1.6.0.jar
quickfixj-core-1.5.3.jar
quickfixj-msg-fix40-1.5.3.jar
quickfixj-msg-fix41-1.5.3.jar
quickfixj-msg-fix42-1.5.3.jar
quickfixj-msg-fix43-1.5.3.jar
quickfixj-msg-fix44-1.5.3.jar
rfa-7.4.0L1.jar
serializer-2.7.1.jar
servlet-api-2.4.jar
simplecaptcha-1.2.1.jar
sitemesh-2.4.2.jar
slf4j-api-1.4.2.jar
slf4j-jcl-1.4.2.jar
slf4j-log4j12-1.4.2.jar
sojo-0.5.0.jar
spring-aop-4.0.6.RELEASE.jar
spring-batch-core-3.0.1.RELEASE.jar
spring-batch-infrastructure-3.0.1.RELEASE.jar
spring-batch-integration-3.0.1.RELEASE.jar
spring-beans-4.0.6.RELEASE.jar
spring-context-4.0.6.RELEASE.jar
spring-context-support-4.0.6.RELEASE.jar
spring-core-4.0.6.RELEASE.jar
spring-expression-4.0.6.RELEASE.jar
spring-flex-1.0.1.RELEASE.jar
spring-integration-core-4.0.3.RELEASE.jar
spring-integration-jms-4.0.3.RELEASE.jar
spring-jdbc-4.0.6.RELEASE.jar
spring-jms-4.0.6.RELEASE.jar
spring-messaging-4.0.6.RELEASE.jar
spring-orm-4.0.6.RELEASE.jar
spring-oxm-1.5.5.jar
spring-retry-1.1.0.RELEASE.jar
spring-security-config-3.2.4.RELEASE.jar
spring-security-core-3.2.4.RELEASE.jar
spring-security-web-3.2.4.RELEASE.jar
spring-test-4.0.6.RELEASE.jar
spring-tx-4.0.6.RELEASE.jar
spring-web-4.0.6.RELEASE.jar
spring-webmvc-4.0.6.RELEASE.jar
spring-webmvc-struts-2.5.6.jar
spring-xml-1.5.5.jar
stax2-api-3.1.1.jar
stax-api-1.0.1.jar
struts2-config-browser-plugin-2.3.16.jar
struts2-core-2.3.15.1.jar
struts2-dojo-plugin-2.3.15.1.jar
struts2-jquery-plugin-3.6.1.jar
struts2-spring-plugin-2.3.15.1.jar
struts2-tiles-plugin-2.3.15.1.jar
strutsjsonplugin-7.0-SNAPSHOT.jar
tiles-api-2.1.3.jar
tiles-core-2.1.3.jar
tiles-jsp-2.1.3.jar
tiles-servlet-2.1.3.jar
twitter4j-core-3.0.jar
urlrewritefilter-3.0.4.jar
validation-api-1.0.0.GA.jar
velocity-1.5.jar
velocity-tools-1.1.jar
woden-1.0-incubating-M7b.jar
woodstox-core-asl-4.2.0.jar
ws-commons-util-1.0.1.jar
wsdl4j-1.6.3.jar
xalan-2.7.1.jar
xercesImpl-2.9.0.jar
xml-apis-1.0.b2.jar
xmlbeans-2.4.0.jar
xmlConverter.swc
xmlgraphics-commons-1.2.jar
xmlParserAPIs-2.0.2.jar
xmlpull-1.1.3.1.jar
xml-resolver-1.2.jar
xmlschema-core-2.1.0.jar
xmlsyndication.swc
xpp3_min-1.1.4c.jar
xstream-1.4.7.jar
xwork-core-2.3.15.1.jar
如果您需要更多信息,请与我们联系。
提前致谢, 拉姆
答案 0 :(得分:0)
尝试从referencedColumnName
EarlyCloseInstrument
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn (name = "INSTRUMENT_TYPE_CODE", updatable = false, insertable = false)
private MCInstrumentType instrumentType;