Persitencia com chave composta
@Table(name = "produto")
public class Produto implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "COD_PRODUTO", nullable = false)
private Integer codProduto;
@Column(name = "DES_PRODUTO")
private String desProduto;
@Column(name = "PRECO_VENDA")
private Double precoVenda;
@Column(name = "PRECO_CUSTO")
private Double precoCusto;
@Column(name = "QTD_ESTOQUE")
private String qtdEstoque;
@JoinColumns({@JoinColumn(name = "COD_SUB_CATEGORIA",
referencedColumnName = "COD_SUB_CATEGORIA"),
@JoinColumn(name = "COD_CATEGORIA",
referencedColumnName = "COD_CATEGORIA")})
@ManyToOne
private SubCategoria subCategoria;
@Entity
@Table(name = "sub_categoria")
public class SubCategoria implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected SubCategoriaPK subCategoriaPK;
@Column(name = "DESCRICAO")
private String descricao;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "subCategoria")
private Collection<Produto> produtoCollection;
@JoinColumn(name = "COD_CATEGORIA", referencedColumnName = "COD_CATEGORIA", insertable = false, updatable = false)
@ManyToOne
private Categoria categoria;
@Entity
@Table(name = "categoria")
@NamedQueries({@NamedQuery(name = "Categoria.findByCodCategoria", query = "SELECT c FROM Categoria c WHERE c.codCategoria = :codCategoria"), @NamedQuery(name = "Categoria.findByDescricao", query = "SELECT c FROM Categoria c WHERE c.descricao = :descricao")})
public class Categoria implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "COD_CATEGORIA", nullable = false)
private Integer codCategoria;
@Column(name = "DESCRICAO")
private String descricao;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "categoria")
private Collection<SubCategoria> subCategoriaCollection;
Create table CATEGORIA (
CATEGORIA_NO Int UNSIGNED NOT NULL AUTO_INCREMENT,
DESCRICAO Varchar(100),
Primary Key (CATEGORIA_NO)) ENGINE = InnoDB; Create table SUB_CATEGORIA (
SUB_CATEGORIA_NO Int UNSIGNED NOT NULL,
CATEGORIA_NO Int UNSIGNED NOT NULL,
DESCRICAO Varchar(100),
Primary Key (SUB_CATEGORIA_NO)) ENGINE = InnoDB; Create table PRODUTO (
PRODUTO_NO Int UNSIGNED NOT NULL AUTO_INCREMENT,
SUB_CATEGORIA_NO Int UNSIGNED NOT NULL,
UNIDADE_NO Int UNSIGNED NOT NULL,
DESCRICAO Varchar(100),
VALOR_VENDA Double,
VALOR_CUSTO Double,
QUANTIDADE Int,
CATEGORIA_NO Int UNSIGNED NOT NULL,
Primary Key (PRODUTO_NO)) ENGINE = InnoDB;
Tenho a seguinte situação: No formulário de produtos preciso selecionar uma categoria em um JComboBox
logo após esta seleção preciso que o JComboBox de subCategorias seja filtrado trazendo
somente as subCategorias relacionadas com a categoria selecionada anteriormente, no entanto
O netBeans gera os beans anotados da forma acima: No entanto desta forma somente é possivel selecionar uma subCategoria e quado clico no botão salvar do formulário a categoria relacionada é automaticamente persistida
Existe um modo alternativo para mapear os objetos para fazer o que preciso? Observe que na classe subCategoria existe uma chave primaria composta. A apicação é desktop swing + jgoodies
Israel Barbosa
Respostas
Dyego Carmo
16/10/2009
Voce precisa selecionar varias subcategorias para o produto ?
Valeu !
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
Desculpe , eu nao entendi BEM a sua duvida...
Voce não conseguindo fazer com que o Produto seja persistido com sua categoria ?
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
A classe PRODUTO detemuma propriedade SUBCATEGORIA , que vai ser preenchida com a subcategoria que voce selecionar em tela , afinal a categoria serviria apenas para filtro...
A classe categoria tem uma propriedade que retorna todas suas subcategorias , entao voce consegue saber quais subcategorias estao cadastradas para aquela categoria...
Em questão a MAPEAMENTO está correto...
Voce esta tendo dificuldade em fazer isto funcionar em JavaServerFaces , eh isso ?
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
Israel Barbosa
16/10/2009
Tenho uma JTable que deve ser ordenada quando clico em uma coluna e filtrada quando digito em um campo
no entanto deve ocorrer uma sincronia entre a visão(dados exibidos pela jtable)
e a lista que contem os dados ou seja deve haver uma sincronia entre os dois. E justamente
isto que não estou conseguindo fazer. Este é um trecho da documentação que cita algo a respeito
o link para a documentação completa é:http://java.sun.com/javase/6/docs/api/javax/swing/table/TableRowSorter.html
This will do all the wiring such that when the user does the appropriate gesture, such as clicking on the column header, the table will visually sort.
JTable's row-based methods and JTable's selection model refer to the view and not the underlying model. Therefore, it is necessary to convert between the two. For example, to get the selection in terms of myModel you need to convert the indices: int[] selection = table.getSelectedRows();
for (int i = 0; i < selection.length; i++) {
selection[i] = table.convertRowIndexToModel(selection[i]);
}
Similarly to select a row in JTable based on a coordinate from the underlying model do the inverse:
table.setRowSelectionInterval(table.convertRowIndexToView(row),
table.convertRowIndexToView(row));
The previous example assumes you have not enabled filtering. If you have enabled filtering convertRowIndexToView will return -1 for locations that are not visible in the view. o código que tenho é o seguinte: fabricanteTable = new JTable(); // Cria uma JTable
fabricanteTable.setModel(fabricanteManagerModel.getFabricanteTableModel()); // Adiciona um tableModel
fabricanteTable.setSelectionModel(new SingleListSelectionAdapter(
fabricanteManagerModel.getFabricanteSelection().getSelectionIndexHolder())); // Permite uma unica seleção fabricanteTable.setRowSorter(fabricanteManagerModel.getRowSorter());//Adiciona o rowSorter responsavel pela ordenação
rowSorter = new TableRowSorter<TableModel>(fabricanteTableModel); // cria o rowSorter e o adiciona o AbstracttableModel nele //Codigo responsavel pela filtragem
@SuppressWarnings("unchecked")
private void observaValorFiltro() {
String text = (String) textoFiltroHolder.getValue();
if (text.length() == 0) {
((DefaultRowSorter<TableModel, Integer>) rowSorter).setRowFilter(null);
} else {
try {
((DefaultRowSorter<TableModel, Integer>) rowSorter)
.setRowFilter(RowFilter.regexFilter(text));
} catch (PatternSyntaxException pse) {
System.err.println("erro");
}
}
}
Dyego Carmo
16/10/2009
1) Ele ordena e se perde quando eh para filtrar
2) Ele nao ordena e nao filtra
3) ele filtra mas nao ordena
outra pergunta , neste seu campo que vc digita o filtro... voce esta digitando expressoes regulares ? Estou pergunta porque sua implementacao está para aceitar apenas expressoes regulares...
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
Pode ser ?
Para que voce esta usando o JGoodies ? Soh para Layout ? ou tah usando para bind tambem ?
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
Verifique a sua lista de spam !
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
(mandem ontem)
Israel Barbosa
16/10/2009
Dyego Carmo
16/10/2009
Mas estas outras solicitacoes devem ser abertas em, outros chamados diferentes deste ,
Posso estar concluindo este ?
Israel Barbosa
16/10/2009