简体   繁体   中英

Trying a best solution?

I'm looking for a solution to my problem. I have 2 java class of domain. Graduacao and Aluno, in Graduacao I have an attribute "graus" that is a Collection. In Aluno class, I have collection attribute "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.

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.

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

A complete example is beyond the scope of 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 ; a very simple example using JComboBox is shown here ; a complete TableModel example with pagination is shown here .

  • Use org.jdesktop.beansbinding , shown here and mentioned here and here .

A number of ancillary links related to this topic are shown in this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM