如果我做一個複合-ID類沒有實現Serializable,如:爲什麼composite-id類必須實現Serializable?
@Entity
@Table(name = "board")
public class Board {
@Id
@Column(name = "keyword_news_id")
private int id;
@Id
@Column(name = "board_no")
private int boardNo;
....
錯誤發生,如:
Caused by: org.hibernate.MappingException: composite-id class must implement Serializable: com.estinternet.news.domain.IssueNewsBoard
at org.hibernate.mapping.RootClass.checkCompositeIdentifier(RootClass.java:263)
at org.hibernate.mapping.RootClass.validate(RootClass.java:244)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1362)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865)
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:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
Hibernate entity classes doesn't need to be Serializable。那麼,爲什麼composite-id類必須實現Serializable?我讀this thread,但它沒有給我足夠的信息。
http://stackoverflow.com/questions/2301259/hibernate-composite-key – Perception 2012-02-14 05:24:49
我讀了,但仍然無法理解的根本原因。 – 2012-02-14 06:39:47
你的'@ IdClass'在哪裏? – 2016-09-07 08:03:01