我无法在@Embedded字段上使用属性访问。
我的课程注释如下:
@Entity
@Table(name = "digitization_order")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
//mapping on getter
private OrderImageData imageData;
@ManyToOne
@JoinColumn(name = "scanner_id")
private Scanner scanner;
public Order() {
}
public long getId() {
return id;
}
@Embedded
@Access(AccessType.PROPERTY)
public OrderImageData getImageData() {
return imageData;
}
[...]
@Embeddable
public class OrderImageData {
@Column(name="controller_revision_no")
private Long controllerRevisionNo;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "order_id")
@OrderColumn(name = "content_order")
private List<OrderContent> contents = new ArrayList<OrderContent>();
[...]
@Entity
@Table(name = "order_content")
public class OrderContent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "uuid")
private String uuid;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "comment")
@OrderColumn(name = "comment_order")
@JoinColumn(name = "order_content_id")
private List<Comment> comments = new ArrayList<Comment>();
private boolean faulty;
private OrderContent() {
}
[...]
@Embeddable
public class Comment {
private CommentType commentType;
private String comment;
private Date date;
private long revisionNo;
//JPA
private Comment() {
}
所有类都有公共访问器,noargument构造函数;
在hibernate创建数据库模式时部署应用程序/时,我得到以下异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [Hibernate-Spring.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: digitization_order, for columns: [org.hibernate.mapping.Column(contents)]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4600)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5097)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5092)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: digitization_order, for columns: [org.hibernate.mapping.Column(contents)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306)
at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:143)
at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:68)
at org.hibernate.mapping.Component.buildType(Component.java:184)
at org.hibernate.mapping.Component.getType(Component.java:177)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:290)
at org.hibernate.mapping.Property.isValid(Property.java:217)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:463)
at org.hibernate.mapping.RootClass.validate(RootClass.java:235)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1332)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1835)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 20 more
将imageData上的访问权限更改为FIELD(将注释从getter移动到字段后)后,堆栈跟踪消失了
任何想法为什么?
答案 0 :(得分:1)
不确定,但OrderImageData
可以从@Access(AccessType.PROPERTY)
方法上的getImageData()
注释继承其访问类型。因此,Hibernate将查找此类属性的映射详细信息,并且不会找到任何异常,从而导致此异常。
尝试将@Access(AccessType.FIELD)
放在OrderImageData
课程上。