我有两张桌子,书架和书。 bookshelf有一个整数数组,用于存储预订的密钥。 实体和表格定义如下。
Table "public.bookshelf”
Column | Type | Modifiers | Storage | Stats target | Description
---------------------+--------------------------------+------------------------------------------------------+----------+--------------+------------------------------------------
id | integer | not null default nextval(‘bookshelf_seq'::regclass) | plain | |
section | character varying(255) | | extended | |
book_ids | integer[] | | extended | |
@Entity(name = "BookShelf")
@Table(name = "bookshelf")
public class BookShelf {
@Id
@Setter
@Getter
@Column(name = "id", insertable = false, updatable = false)
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
@Getter
@Setter
private String section;
@Getter
@Setter
@OneToMany(mappedBy = "bookShelf")
private List<Book> books = new ArrayList<>();
}
Table "public.book”
Column | Type | Modifiers | Storage | Stats target | Description
---------------------+--------------------------------+---------------------------------------------------+----------+--------------+------------------------------------------
id | integer | not null default nextval(‘book_seq'::regclass) | plain | |
name | character varying(255) | | extended | |
@Entity(name = "Book")
@Table(name = "book")
public class Book {
@Id
@Setter
@Getter
@Column(name = "id", insertable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Getter
@Setter
@Column(name = "name")
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinFormula("select b.id from bookshelf b where id = any(b.book_ids)")
private BookShelf bookShelf ;
}
我得到了org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column
我单独使用hibernate进行了一些测试,并没有看到这个问题,所以我想这可能是一个春天的事情,但摆脱春天不是选择。
这是我的依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>