| 
					
						 I am trying to write a sample app that uses the joined-subclass feature in hibernate. I am using the Empleado (Empleyed) and Contador (Counter).
  I can only run the method to add a counter, I can not delete, or list. I dont know what is the problem, help me please!!!
  Any help would be get me is very welcome.
  Sorry about my English.
  Mapped The Employee <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http.......://......hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 14-oct-2009 18:49:38 by Hibernate Tools 3.2.1.GA polymorphism="implicit"--> <hibernate-mapping> <class catalog="escuela" name="ClasesYMapeos.Empleado" table="empleados">
  <id name="empleadoId" column="EmpleadoID"> <generator class="identity"/> </id>
  <property name="nombre" type="string"> <column length="45" name="Nombre" not-null="true"/> </property> <property name="apellido" type="string"> <column length="45" name="Apellido" not-null="true"/> </property>
  <joined-subclass name="ClasesYMapeos.Contador" table="Contadores"> <key column="EmpleadoId"/> <property column="Sector" name="Sector" type="java.lang.String"/> </joined-subclass> </class> </hibernate-mapping>
 
 
  Clase Empleado (Class employee) package ClasesYMapeos; // Generated 14-oct-2009 18:49:36 by Hibernate Tools 3.2.1.GA
 
  public class Empleado implements java.io.Serializable {
 
  private int empleadoId; private String nombre; private String apellido;
  public Empleado() { }
  public Empleado(int empleadoId, String nombre, String apellido) { this.empleadoId = empleadoId; this.nombre = nombre; this.apellido = apellido; }
  public int getEmpleadoId() { return this.empleadoId; }
  public void setEmpleadoId(int empleadoId) { this.empleadoId = empleadoId; } public String getNombre() { return this.nombre; }
  public void setNombre(String nombre) { this.nombre = nombre; } public String getApellido() { return this.apellido; }
  public void setApellido(String apellido) { this.apellido = apellido; } }
  Clase Contador (Class Counter) Package ClasesYMapeos;
  public class Contador extends Empleado implements java.io.Serializable{
 
  private int empleadoId; private String sector;
  public Contador() { }
  public Contador(String sector) { this.sector = sector; }
 
  public int getEmpleadoId() { return this.empleadoId; }
  public void setEmpleadoId(int empleadoId) { this.empleadoId = empleadoId; }
  public String getSector() { return this.sector; }
  public void setSector(String sector) { this.sector = sector; }
  }
  Clase ServiciosContadores (Class ServiceCounter)
  package Servicios;
  /* Clases Que Realizamos */ import ClasesYMapeos.Contador; import HibernateUtil.MySessionFactory; /* Java util */ import java.util.List; /* Las clases necesarias pra trabajar con Hibernate */ import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction;
  public class ServiciosContadores {
  public boolean newContador(Contador unContador) { boolean creado = false; Session session = MySessionFactory.getSession(); Transaction tx = null; try{ tx = session.beginTransaction(); session.save(unContador); tx.commit(); creado = true; }catch(HibernateException he){ if(tx!=null) tx.rollback(); System.out.println(he.getMessage()); }finally{ session.close(); } return creado; }
  public List<Contador> listCont(){ /* Iniciamo y tomamos la instancia de la session */ Session miSession = MySessionFactory.getSession(); Transaction tx = null; List<Contador> contadores = null;
  try{ miSession.beginTransaction(); /* Realizamos la consulta en HQL */ String hql = "FROM Contador"; Query q = miSession.createQuery(hql); contadores = q.list(); /* retornamos una lista de categorias */ return contadores; }catch(HibernateException he){ /* si pasa algun errro volvemos atrar la tansaccion */ if(tx!=null) tx.rollback(); }finally{ miSession.close(); return contadores; /* Pueder ser NULL o una lista de Categorias */ } } }
  waiting a solution. Thank!
  NicoStone. 
					
  
						
					 |