Estoy tratando de hacer un crud en Strud2 con hibernate y no consigo combinar dos tablas . Me puede ayudar
La 1 Tabla es Trama
@Entity
@Table(name="trama", catalog="bd_1")
public class Trama implements java.io.Serializable {
private int traNoca; //Int
private int catNoca; //Enlace con categoria
private String tradat; //Dato sin importancia
public Trama() {}
public Trama(int traNoca, int catNoca, String tradat)
{this.traNoca = traNoca; this.catNoca = catNoca; this.tradat = tradat; }
@Id
@Column(name="tra_noca", nullable=false)
public int getTraNoca() {return this.traNoca;} ES
public void setTraNoca(int traNoca) {this.traNoca = traNoca; }
@Column(name="cat_noca", nullable=false)
public int getCatNoca() {return this.catNoca;}
public void setCatNoca(int catNoca) {this.catNoca = catNoca;}
@Column(name="tra_dat", nullable=false, length=45)
public String getTradat() {return this.tradat;}
public void setTradat(String tradat) { this.tradat = tradat; }
}
Este es Su mapeado
<hibernate-mapping>
<class name="entidad.Trama" table="trama" catalog="bd_1">
<id name="TraNoca" type="int">
<column name="tra_noca">
<generator class="assigned"></generator>
</id>
<property name="CatNoca" type="int">
<column name="cat_noca">
</property>
<property name="Tradat" type="string">
<column name="cat_dat" length="50">
</property>
</class>
</hibernate-mapping>
La 2 Tabla es Categoria que es la principal
package entidad;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "trama", catalog = "bd_1" )
public class Categoria implements java.io.Serializable {
private int catNoca;
private String catNom;
public Categoria() {}
public Categoria(int catNoca, String catNom)
{this.catNoca = catNoca; this.catNom = catNom;}
@Id
@Column(name="cat_noca", nullable=false)
public int getCatNoca() {return this.catNoca;}
public void setCatNoca(int catNoca) {this.catNoca = catNoca;}
@Column(name="cat_nom", nullable=false, length=45)
public String getCatNom() {return this.catNom;}
public void setCatNom(String catNom) { this.catNom = catNom; }
}
Este es el Mapeado
<hibernate-mapping>
<class name="entidad.Categoria" table="categoria" catalog="bd_1">
<id name="CatNoca" type="int">
<column name="cat_noca">
<generator class="assigned"></generator>
</id>
<property name="CatNom" type="string">
<column name="cat_nom" length="50">
</property>
</class>
</hibernate-mapping>
Y este es Strut2 que manda la orden
public void detalle2(String noca,T entity) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction beginTransaction = session.beginTransaction();
session.createSQLQuery("select c.CatNoca, c.CatNom, t.CatNoca, t.TraNoca, t.CatNom, t.tradat from Trama t INNER JOIN Categoria c ON t.CatNoca="+entity);
beginTransaction.commit();
session.close();
}
La entidad me lo manda
package acciones;
import static com.opensymphony.xwork2.Action.INPUT;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import entidad.Categoria;
import java.util.List;
import servicio.ServicioCategoria;
public class CategoriaAction extends ActionSupport {
private ServicioCategoria sc= new ServicioCategoria();
private List<Categoria> lstCat;
private Categoria cat;
private String m;//NO IMPORTANTE PARA LA DUDA
private String i;//NO IMPORTANTE PARA LA DUDA
private Integer noca;
@Override
public String input() throws Exception {
if (getNoca()!=null) {setCat(sc.find(noca));}
return INPUT;}
public String detalle2() throws Exception {
if (getNoca()!=null) {setCat(sc.find(noca)); }
return INPUT;}
@Override
public String execute() throws Exception {return SUCCESS;}
public String save() { sc.save(getCat()); return "ok"; }
public String remove(){ sc.remove(getNoca()); return "ok"; }
public String list() throws Exception { lstCat=sc.findAll(); return execute();}
public String search() throws Exception { lstCat = sc.search(m);return execute();}
public String indice() throws Exception { lstCat = sc.search(i);return execute();}
//<editor-fold defaultstate="collapsed" desc="Getter y Setter">
public ServicioCategoria getSc() {return sc; }
public void setSc(ServicioCategoria sc) {this.sc = sc;}
public String getM() { return m;}
public void setM(String m) { this.m = m; }
public String getI() { return i; }
public void setI(String i) { this.i = i;}
public Integer getNoca() { return noca; }
public void setNoca(Integer noca) {this.noca = noca;}
public Categoria getCat() {return cat;}
public void setCat(Categoria cat) { this.cat = cat; }
public List<Categoria> getLstCat() {return lstCat;}
public void setLstCat(List<Categoria> lstCat) {this.lstCat = lstCat;}
//</editor-fold>
}
Ayudada por
public class ServicioCategoria extends AbstractFacade<Categoria> {
public ServicioCategoria() {super(Categoria.class);}
//CATEGORIA
public List<Categoria> findAll() {return super.findAll();}
public void save(Categoria cat) {super.createEdit(cat);}
public void remove(int noca) {
final Categoria find = super.find(noca);
if (find!=null){
super.remove(find);}
}
public Categoria find (int noca) {
return super.find(noca);
}
//TRAMA
}
El JSP SOLO MUESTRA los datos de la tabla categoria
No Consigo unir las tablas estoy desesperado