Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Hibernate

    Salve
    Sono nuovo di questo sito ... e vi ringrazio anticipatamente ....
    Volevo un aiuto sulle annotazioni hibernate ....
    Sto cercando di usare Jboss Seam ... cone le Hibernate annotation ... Ma ho delle difficolta a mappare le relazioni. La situazione è la seguente ...
    Ho due classi, User e Prodotto ed una classe carrello
    Nel carrello dovrei inserire user e prodotto volta volta per volta ....
    Io nel codice li inserisco come oggetti nel carrello ma mi vanno in errore le annotation ...

  2. #2
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,328

    Moderazione

    Dovresti anche dire quali errori ottieni e, magari, postare anche il codice relativo... altrimenti come fanno gli utenti a darti dei suggerimenti se non sanno dove mettere le mani?

    Ti invito anche a leggere il Regolamento interno: ci sono diverse cose da sapere sull'apertura delle discussioni, sui titoli e sul posting del codice.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  3. #3
    Ho le seguenti Tabelle :
    User {
    id primarykey int
    username varchar
    password varchar}
    Product {
    id_product primary key in t
    nome varchar
    prezzo double}
    Basket {
    user foreignkey int
    product foreignkey int
    quantity int
    price double
    total double}
    Ho scritto le seguenti classi con le hibernate annotation
    Basket.java
    package org.domain.provaregistrazionenew.entity;
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    import javax.persistence.JoinColumn;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.GeneratedValue;
    import javax.persistence.JoinColumns;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.OneToOne;
    import javax.persistence.PrimaryKeyJoinColumn;
    import javax.persistence.Table;
    import javax.persistence.Version;
    import org.hibernate.annotations.ForeignKey;
    import org.hibernate.validator.Length;
    import org.hibernate.validator.NotNull;
    import org.jboss.resteasy.annotations.providers.jaxb.json .Mapped;
    import org.jboss.seam.ScopeType;
    import org.jboss.seam.annotations.In;
    import org.jboss.seam.annotations.Name;
    import org.jboss.seam.annotations.Scope;

    @Entity
    @Name("basket")
    @Scope(ScopeType.EVENT)
    @Table(name="basket")
    public class Basket implements Serializable
    {
    private static final long serialVersionUID = 1L;
    private User user;
    private Product product;
    private Double price;
    private Double total;
    private int quantity;

    public Basket (){}
    public Basket (Product product,User user, Double price, Double total, int quantity){
    this.setProduct(product);
    this.setUser(user);
    this.price= price;
    this.total= total;
    this.quantity= quantity;
    }
    public void setPrice(Double price) {
    this.price = price;
    }
    public Double getPrice() {
    return price; }
    public void setQuantity(int quantity) {
    this.quantity = quantity;
    }
    public int getQuantity() {
    return quantity;
    }
    public void setTotal(Double total) {
    this.total = total;
    }
    public Double getTotal() {
    return total; }
    public void setProduct(Product product) {
    this.product = product;
    }
    @OneToOne
    public Product getProduct() {
    return product; }
    public void setUser(User user) {
    this.user = user;
    }
    @OneToOne
    public User getUser() {
    return user; }
    User.java
    package org.domain.provaregistrazionenew.entity;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.GeneratedValue;
    import javax.persistence.JoinColumn;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
    import javax.persistence.Version;
    import org.hibernate.validator.Length;
    import org.hibernate.validator.NotNull;
    import org.jboss.seam.ScopeType;
    import org.jboss.seam.annotations.Name;
    import org.jboss.seam.annotations.Scope;

    @Entity
    @Name("user")
    @Scope(ScopeType.SESSION)
    @Table(name="user")
    public class User implements Serializable
    {
    private static final long serialVersionUID = 1881413500711441951L;
    private String username;
    private String password;
    private Long id;
    public User(Long id, String password, String username)
    {
    this.id=id;
    this.password = password;
    this.username = username;
    }
    public User() {}
    @NotNull @Length(min=5, max=15)
    public String getPassword()
    { return password; }
    public void setPassword(String password)
    { this.password = password;}

    @NotNull @Length(min=5, max=15)
    public String getUsername()
    { return username;}

    public void setUsername(String username)
    { this.username = username; }

    public void setId(Long id) { this.id = id;}
    @Id @NotNull @Column(name="ID")
    public Long getId() {
    return id;}
    }

    Product.java
    package org.domain.provaregistrazionenew.entity;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.GeneratedValue;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
    import javax.persistence.Version;
    import org.hibernate.validator.Length;
    import org.hibernate.validator.NotNull;
    import org.jboss.seam.ScopeType;
    import org.jboss.seam.annotations.Name;
    import org.jboss.seam.annotations.Scope;

    @Entity
    @Name("product")
    @Scope(ScopeType.EVENT)
    @Table(name="product")
    public class Product implements Serializable
    { private static final long serialVersionUID = -7059910699234962558L;
    private Long id_product;
    private String name;
    private Double price;
    public Product (){}
    public Product (long id_prodotto, String nome, Double prezzo){
    this.id_product= id_prodotto;
    this.name= nome;
    this.price= prezzo;
    }
    public void setNome(String nome) {
    this.name = nome; }
    @NotNull
    public String getNome() {
    return name;
    }
    public void setId_prodotto(Long id_prodotto) {
    this.id_product = id_prodotto;
    }
    @Id @NotNull @Column(name="id_prodotto")
    public Long getId_prodotto() {
    return id_product;
    }
    public void setPrezzo(Double prezzo) {
    this.price = prezzo;
    }
    @NotNull
    public Double getPrezzo() {
    return price;
    }
    }
    public void setUser(User user) {
    this.user = user;}
    @NotNull@Id
    public User getUser() {
    return user;
    }
    public void setProduct(Product product) {
    this.product = product;
    }
    @NotNull
    public Product getProduct() {
    return product;
    }
    Senza le Notation e quindi senza il basket tutto funzionava ... il problema è che avendo creato il carrello e avendo messo altre annotation ovvero quelle sulle relazioni non mi funziona e non mi riesce ad istanziare la componente di SEAM }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.