2
我有一個超類休眠 - 連續映射到兩個子類
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "entity_type", discriminatorType = DiscriminatorType.STRING)
@Table(name = "my_super")
public abstract class MySuper{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "super_id")
private Long id;
}
和兩個子類
@Entity
@DiscriminatorValue("sub1")
public class Sub1 extends MySuper {}
@Entity
@DiscriminatorValue("sub2")
public class Sub2 extends MySuper {}
現在,如果其他類有兩個在它這些子類的,是有可能通過相同的連接表實例化其中的一個 - 相同的行?
例如:
@Entity
@Table(name = "caller")
public class Caller{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "caller_id")
Long id;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "caller_super", joinColumns = @JoinColumn(name = "caller_id"), inverseJoinColumns = @JoinColumn(name = "super_id"))
private Set<Sub1> sub1s;
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "caller_super", joinColumns = @JoinColumn(name = "caller_id"), inverseJoinColumns = @JoinColumn(name = "super_id"))
Sub2 sub2;
}
我不斷收到試圖實例化一個來電的對象時,這個錯誤:
org.springframework.orm.hibernate3.HibernateSystemException: could not set a field value by reflection setter of my.test.Caller.sub2; nested exception is org.hibernate.PropertyAccessException: could not set a field value by reflection setter of my.test.Caller.sub2
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:102)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:368)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
nested exception is org.hibernate.PropertyAccessException: could not set a field value by reflection setter
謝謝!我改變了連接表,它工作。 – imgr8 2012-04-04 01:46:01
你好.. – erimerturk 2012-04-04 05:28:49