0

我无法在 @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() {
}

所有类都有公共访问器,无参数构造器;

当部署应用程序/当休眠正在创建数据库模式时 - 我得到以下异常:

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 移动到字段后)

任何想法为什么?

4

1 回答 1

1

不确定,但可以从放置在方法上OrderImageData的注释继承其访问类型。因此,Hibernate 将查找有关此类属性的映射详细信息,但找不到任何内容,从而导致此异常。@Access(AccessType.PROPERTY)getImageData()

尝试上课@Access(AccessType.FIELD)OrderImageData

于 2012-05-15T15:00:38.637 回答