休眠是否可能使用名称不同的getter作为字段?
....
private ComplexObject test;
@Access(AccessType.PROPERTY)
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "number_format")
public ComplexObject getSomeStuff() {
....
return test;
}
....
我总是得到异常
原因:javax.persistence.PersistenceException:[PersistenceUnit: default]无法在以下位置建立Hibernate SessionFactory org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249) 〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access $ 600(EntityManagerFactoryBuilderImpl.java:120) 〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:860) 〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:850) 〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) 〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]在 org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) 〜[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE]在 org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) 〜[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE]在 org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) 〜[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE]在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) 〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) 〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] ... 21个常见帧 省略
原因:org.hibernate.MappingException:无法确定类型:ComplexObject,在表:table,对于列: [org.hibernate.mapping.Column(extension_form_element_number_format)] 在org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:349) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:322) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.mapping.Property.isValid(Property.java:241) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.mapping.RootClass.validate(RootClass.java:270) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.cfg.Configuration.validate(Configuration.java:1360) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) 〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:857) 〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final] ... 29 常见的框架省略了
如果方法不是由字段命名的(在本例中为getTest())。
谢谢