开发者社区> 问答> 正文

两表一对多,加了外键联系后,报错,两张表的内容都显示不出来了?报错

package com.inzyme.p2p.test;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.inzy.framework.core.common.entity.IdEntity;

import com.inzyme.p2p.finance.transcation.entity.TranscationEntity;

@Entity
@Table(name = "test_account", schema = "")
public class TestEntity {
	private String id;
	private String account;
	private String host;
	private String type;
	private String accountname;
	private String money;
	private String state;
	private String note;

	private List<TradeEntity> trade = new ArrayList<TradeEntity>();

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "testentity")
	public List<TradeEntity> getTrade() {
		return trade;
	}

	public void setTrade(List<TradeEntity> trade) {
		this.trade = trade;
	}

	@Id
	@Column(name = "id", nullable = false, length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "账号", nullable = true, length = 32)
	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	@Column(name = "户主", nullable = true, length = 32)
	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	@Column(name = "账户类型", nullable = true, length = 2)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "账户名称", nullable = true, length = 50)
	public String getAccountname() {
		return accountname;
	}

	public void setAccountname(String accountname) {
		this.accountname = accountname;
	}

	@Column(name = "余额", nullable = true, length = 32)
	public String getMoney() {
		return money;
	}

	public void setMoney(String money) {
		this.money = money;
	}

	@Column(name = "账户状态", nullable = true, length = 2)
	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	@Column(name = "备注", nullable = true, length = 32)
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

}



展开
收起
爱吃鱼的程序员 2020-06-09 13:13:39 603 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    这是子表的packagecom.inzyme.p2p.test;importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persistence.FetchType;importjavax.persistence.GeneratedValue;importjavax.persistence.Id;importjavax.persistence.JoinColumn;importjavax.persistence.ManyToOne;importjavax.persistence.Table;importorg.hibernate.annotations.GenericGenerator;importorg.inzy.framework.core.common.entity.IdEntity;importorg.inzy.framework.poi.excel.annotation.Excel;@Entity@Table(name="test_trade",schema="")publicclassTradeEntity{@Excel(name="编号")privateStringid;@Excel(name="所属账户")privateTestEntitytestentity;@Excel(name="交易科目")privateStringtitle;@Excel(name="借贷方向")privateStringdirection;@Excel(name="交易金额")privatedoublemoney;@Excel(name="备注")privateStringnote;@Excel(name="交易日期")privatejava.util.Dateaccountdate;@ManyToOne(fetch=FetchType.LAZY)@JoinColumn(name="accountid")publicTestEntitygetTestentity(){returntestentity;}publicvoidsetTestentity(TestEntitytestentity){this.testentity=testentity;}@Column(name="title",nullable=true,length=50)publicStringgetTitle(){returntitle;}publicvoidsetTitle(Stringtitle){this.title=title;}@Column(name="direction",nullable=false,length=2)publicStringgetDirection(){returndirection;}publicvoidsetDirection(Stringdirection){this.direction=direction;}@Column(name="trademoney",nullable=false,length=10)publicdoublegetMoney(){returnmoney;}publicvoidsetMoney(doublemoney){this.money=money;}@Column(name="note",nullable=true)publicStringgetNote(){returnnote;}publicvoidsetNote(Stringnote){this.note=note;}@Column(name="date",nullable=false,length=20)publicjava.util.DategetAccountdate(){returnaccountdate;}publicvoidsetAccountdate(java.util.Dateaccountdate){this.accountdate=accountdate;}@Id@Column(name="id",nullable=false,length=32)publicStringgetId(){returnid;}publicvoidsetId(Stringid){this.id=id;}}



    2020-06-09 13:13:58
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
RowKey与索引设计:技巧与案例分析 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载