【问题标题】:one-to-many unidirectional mapping with compound使用复合的一对多单向映射
【发布时间】:2013-06-04 19:49:59
【问题描述】:

我正在努力应对以下情况:

我有 2 张桌子:

RESULTS (
`L_ID` int(10) unsigned NOT NULL,
`PRIZE` int(10) unsigned NOT NULL,
`SECONDARY_PRIZE` int(10) unsigned NOT NULL,
PRIMARY KEY (`L_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |


STATISTICS (
`L_ID` int(10) unsigned NOT NULL,
`F_TYPE` int(10) unsigned NOT NULL,
`RANK` varchar(2) NOT NULL,
`WINNERS` int(10) unsigned NOT NULL,
`PRIZE` int(10) unsigned NOT NULL,
PRIMARY KEY (`L_ID`,`F_TYPE`,`RANK`),
KEY `L_ID_FK_idx` (`L_ID`),
CONSTRAINT `L_ID` FOREIGN KEY (`L_ID`) REFERENCES `RESULTS` (`L_ID`) ON DELETE NO ACTION ON UPDATE  NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

还有以下类:

@Embeddable
public class StatisticId implements Serializable {

  @Column(name = "L_ID", unique=false, nullable=false, updatable=true, insertable=true)
  private long lId;

  @Column(name = "F_TYPE", unique=false, nullable=false, updatable=true, insertable=true)
  private int fType;

  @Column(name = "RANK_ID", unique = false, nullable = false, updatable = true, insertable = true, length = 2)
  private String rankId;

   ..Getters\Setters...
}

统计类:

@Entity
@Table(name = "STATISTICS", uniqueConstraints = {})
public class Statistic implements Serializable {

  @EmbeddedId   
  @AttributeOverrides({ 
    @AttributeOverride(name = "lId", column = @Column(name = "L_ID", unique = false, nullable = false, insertable = true, updatable = true)),
    @AttributeOverride(name = "fType", column = @Column(name = "F_TYPE", unique = false, nullable = false, insertable = true, updatable = true)),
    @AttributeOverride(name = "rankId", column = @Column(name = "RANK_ID", unique = false, nullable = false, insertable = true, updatable = true, length = 2))
  })
  private StatisticId id;


  @Column(name = "WINNERS", unique = false, nullable = false, updatable = true, insertable = true)
  private long winners;

  @Column(name = "PRIZE", unique = false, nullable = false, updatable = true, insertable = true)
  private long prize;
}

最后是结果表:

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(name = "RESULTS")
public class Result extends Form {

@Id
@Column(name = "L_ID", unique = true, nullable = false, insertable = false, updatable = false)    
    private long lId;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name="StatisticsResults",
    joinColumns = { @JoinColumn(name="id.lId") }, 
    inverseJoinColumns = { @JoinColumn(name="lId") }
)
private List<Statistic> statistics;

@Column(name = "PRIZE", unique = false, nullable = false, insertable = true, updatable = true)
private long prize;

@Column(name = "SECONDARY_PRIZE", unique = false, nullable = true, insertable = true, updatable = true)
private long secondaryPrize;

}

我使用 Hibernate4.3beta 和它的 proxool 池连接。

我得到的例外是:

org.hibernate.AnnotationException: A Foreign key refering    
com.btl.server.database.beans.Statistic from com.btl.server.database.beans.Result has the wrong  
number of column. should be 2

我在拧什么??

感谢您耐心阅读本文!

【问题讨论】:

    标签: hibernate hibernate-mapping


    【解决方案1】:

    解决了!!

    问题是 HIbernate4.3 beta 版本,一旦我切换到 4.2.1Final,它就像魔法一样工作!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 2019-01-08
      • 2012-09-04
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 2011-04-24
      相关资源
      最近更新 更多