[英]Trying a best solution?
I'm looking for a solution to my problem. 我正在寻找解决问题的方法。 I have 2 java class of domain.
我有2个java类的域名。 Graduacao and Aluno, in Graduacao I have an attribute "graus" that is a Collection.
Graduacao和Aluno,在Graduacao我有一个属性“graus”,这是一个集合。 In Aluno class, I have collection attribute "List graduacao".
在Aluno类中,我有收集属性“List graduacao”。 I add the Graduacao in a JComboBox about ComboBoxModel and when user selected a Graduacao I have a JList that show the "graus" of Graduacao.
我在JComboBox中添加了关于ComboBoxModel的Graduacao,当用户选择了Graduacao时,我有一个显示Graduacao“graus”的JList。
What I need is get Graduacao and graus that user choose and add to Aluno and persist after show results in a JTable with AbstractTableModel. 我需要的是获得用户选择并添加到Aluno的Graduacao和graus,并在使用AbstractTableModel的JTable中显示结果后继续。
I'm trying this 我正在尝试这个
@Entity
@Table(name="graduacao")
public class Graduacao {
@Id @GeneratedValue
private Integer id;
@NotNull @Column(unique = true)
private String graduacao;
@ElementCollection
@CollectionTable(name="graduacao_grau", joinColumns=@JoinColumn(name="id_graduacao"))
@Column(name="grau")
private List<String> graus;
//get and set
@Entity
@Table(name="aluno")
public class Aluno {
@Id @GeneratedValue
private Integer id;
//informacoes gerais
@NotNull
private String nome;
private String cpf;
private String rg;
private String nomePai;
private String nomeMae;
@Temporal(TemporalType.DATE)
private Date dtNascimento;
@Temporal(TemporalType.TIMESTAMP)
private Date dtCadastro;
private String status;
private String observacoes;
//logradouro
private String endereco;
private String bairro;
private String complemento;
private String cidade;
private String cep;
@Enumerated(EnumType.STRING)
private EstadoBrasileiro uf;
//contato
@ElementCollection
@CollectionTable(name="telefone_aluno", joinColumns=@JoinColumn(name="id_aluno"))
@Column(name="telefone")
private List<String> telefones;
private String email;
//graduacao
@OneToMany @JoinColumn(name="id_aluno")
private List<Graduacao> graduacao;
@Temporal(TemporalType.DATE)
private Date dataGraduou;
//federacao
@OneToMany @JoinColumn(name="id_federacao")
private List<Federacao> federacao;
//get and set
here the print 在这里打印
/** edit */ I solved the problem, here the project: http://www.4shared.com/zip/1Gbj-IZLce/project_example.html / **编辑* /我解决了这个问题,这里是项目: http : //www.4shared.com/zip/1Gbj-IZLce/project_example.html
A complete example is beyond the scope of StackOverflow. 一个完整的示例超出了StackOverflow的范围。 Two approaches are common, although neither is simple:
有两种方法很常见,但两种方法都不简单:
Create a custom TableModel
that uses JPA queries and entities to implement the methods required by AbstractTableModel
; 创建一个使用JPA查询和实体的自定义
TableModel
来实现AbstractTableModel
所需的方法; a very simple example using JComboBox
is shown here ; 这里显示了一个使用
JComboBox
简单示例; a complete TableModel
example with pagination is shown here . 此处显示了具有分页的完整
TableModel
示例。
Use org.jdesktop.beansbinding
, shown here and mentioned here and here . 使用
org.jdesktop.beansbinding
, 此处显示并在此处和此处提及。
A number of ancillary links related to this topic are shown in this answer . 本答案中显示了与此主题相关的许多辅助链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.