我是靠谱客的博主 清新吐司,最近开发中收集的这篇文章主要介绍java ee映射_映射多对一外键Java EE,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

这是作业,我不明白,所以帮助表示赞赏。该系统是奥运奖牌理货模拟器。

我们有一个Events表和一个Countries表:

statement.execute("create table EVENTS (EVENTNUMBER integer primary key not null, EVENTNAME varchar(32), " +

" GENDER varchar(5), GOLD integer, SILVER integer, BRONZE integer)");

statement.execute("create table COUNTRIES (COUNTRYID integer primary key not null, NAME varchar(32)," +

"TOTALGOLD integer, TOTALSILVER integer, TOTALBRONZE integer)");这些涉及实体:

@Entity

@Table(name = "COUNTRIES")

public class Country implements Serializable

{

@Id

private int countryID; // This is the primary key

private String name;

private int totalGold;

private int totalSilver;

private int totalBronze;

//getters, setters omitted

@Entity

@Table(name = "EVENTS")

public class Event implements Serializable

{

@Id

private int eventNumber; // This is the primary key

private String eventName;

private String gender; // Men, Women or Mixed

@ManyToOne(optional=false)

@JoinColumn(name="COUNTRYID", nullable=false, updatable=false)

private Country gold, silver, bronze;

//getter, setter methods omitted问题是为事件添加三个国家实例变量来代表黄金,白银和铜牌赢家,并包含关系类型。对我来说,这是一个多对一的理解。但是,当我尝试运行这个时,我得到一个关于连接错误的错误,因为它应该只允许一个写,其余的只读。

因此,我将JoinColumn更改为insertable = false并且出现错误:列'COUNTRYID'或者不在FROM列表中的任何表中,或者出现在联接规范中,并且超出了联接规范的范围或出现在HAVING子句中并不在GROUP BY列表中。

在我的QueriesBean中,这个方法被击中了:

public List getEvents()

{

List eventList = null;

Query query = em.createQuery("SELECT e FROM Event e");

eventList = (List) query.getResultList();

return eventList;

}也许有人可以给我一些指导?

最后

以上就是清新吐司为你收集整理的java ee映射_映射多对一外键Java EE的全部内容,希望文章能够帮你解决java ee映射_映射多对一外键Java EE所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

评论列表共有 0 条评论

立即
投稿
返回
顶部