Intento llegar a un campo en una tabla y no sé cómo hacerlo. Tengo una tabla donde tengo todos los datos (TespEolReference), tengo otra tabla intermedia que se llama tabla EolMedia donde está el hashset hacia TespTaxon y el campo taxonRecordId, que es el campo que estoy interesado en actualizar. Lo estoy desarrollando para crear un nuevo registro. Me deja actualizar los registros que ya hay en BBDD pero al ingresar uno nuevo no lo muestra en el formulario ya que no esta guardando el id necesario y relacionado. Dejo mi código para que lo veas.
Gracias a todos chicos!
TespEolReferenceData.java
* TespEolReference generated by hbm2java
*/
public class TespEolReferenceData implements java.io.Serializable {
private String idreference;
private TespTPublicationtype tespTPublicationtype;
private String fullReference;
private Set<TespEolmedia> tespEolmedias = new HashSet(0);
private BigDecimal idtaxon;
private String scientificname;
}
TespEolReference.java
public class TespEolReference extends AbstractGenericEntity implements java.io.Serializable {
private Long idreference;
private TespTPublicationtype tespTPublicationtype;
private String fullReference;
private Set tespEolmedias = new HashSet(0);
}
TespEolMedia.java
public class TespEolmedia extends AbstractGenericEntity implements java.io.Serializable {
private BigDecimal idmedia;
private TespTAudience tespTAudience;
private TespTType tespTType;
private Set tespTaxons = new HashSet(0);
private Set tespEolReferences = new HashSet(0);
}
TespTaxon.java
public class TespTaxon extends AbstractGenericEntity implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private BigDecimal taxonid;
private TespTAmbitos tespTAmbitos;
private BigDecimal taxonrecordid;
private BigDecimal idtaxonomicstatus;
private String source;
private String tmpDatasetid;
private Set<TespEolmedia> tespEolmedias = new HashSet<TespEolmedia>(0);
private Set<TespEolReference> testEolReference = new HashSet<TespEolReference>(0);
}
ApplicationServiceUtils.java
public static TespEolReference getTespEolReference(
TespEolReferenceData tespEolReferenceData) {
try {
TespEolReference tespEolReference = new TespEolReference();
if(tespEolReferenceData.getIdreference() != null && !tespEolReferenceData.getIdreference().equals("")) {
tespEolReference.setIdreference(new Long(tespEolReferenceData.getIdreference()));
}
tespEolReference.setFullReference(tespEolReferenceData.getFullReference());
**if(tespEolReferenceData.getIdtaxon() != null && !tespEolReferenceData.getIdtaxon().equals("")) {
// TespEolmedia tespEolmedia = new TespEolmedia();
TespTaxon tespTaxon = new TespTaxon();
tespTaxon.setTaxonrecordid(new BigDecimal(tespEolReferenceData.getIdtaxon()));
HashSet tespTaxons = new HashSet();
tespTaxons.add(tespTaxon);
tespEolReference.setTespEolmedias(tespTaxons);
}**
return tespEolReference;
} catch (Exception e) {
LOGGER.error("Ha ocurrido un error en getTespEolReference: "
+ e.getMessage());
return null;
}
}
public static TespEolReferenceData getTespEolReferenceData(
TespEolReference tespEolReference) {
try {
TespEolReferenceData tespEolReferenceData = new TespEolReferenceData();
tespEolReferenceData.setIdreference(tespEolReference.getIdreference().toString());
tespEolReferenceData.setFullReference(tespEolReference.getFullReference());
return tespEolReferenceData ;
} catch (Exception e) {
LOGGER.error("Ha ocurrido un error en getTespEolReferenceData: "
+ e.getMessage());
return null;
}
}
TespEolReference.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
<hibernate-mapping>
<class name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolReference" table="TESP_EOL_REFERENCE" schema="DBA_IEPNB">
<id name="idreference" type="long">
<column name="IDREFERENCE" precision="22" scale="0" />
<generator class="sequence-identity" >
<param name="sequence">SEQ_TESP_EOL_REFERENCE</param>
</generator>
</id>
<many-to-one name="tespTPublicationtype" class="es.magrama.iepnb.especies.bom.hibernate.tables.TespTPublicationtype" fetch="select">
<column name="IDPUBLICATIONTYPE" precision="22" scale="0" />
</many-to-one>
<property name="fullReference" type="string">
<column name="FULL_REFERENCE" />
</property>
<property name="primarytitle" type="string">
<column name="PRIMARYTITLE" />
</property>
<property name="title" type="string">
<column name="TITLE" />
</property>
</class>
</hibernate-mapping>
TespEolMedia.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolmedia" table="TESP_EOLMEDIA" schema="DBA_IEPNB">
<id name="idmedia" type="big_decimal">
<column name="IDMEDIA" precision="22" scale="0" />
<generator class="assigned" />
</id>
<set name="tespTaxons" table="TESP_TAXON_EOL_MEDIA" inverse="true" lazy="true" fetch="select">
<key>
<column name="IDMEDIA" precision="22" scale="0" not-null="true" />
</key>
<many-to-many entity-name="es.magrama.iepnb.especies.bom.hibernate.tables.TespTaxon">
<column name="TAXONID" precision="22" scale="0" not-null="true" />
</many-to-many>
</set>
<set name="tespEolReferences" table="TESP_EOLMEDIAEOLREFERENCE" inverse="false" lazy="false" fetch="select">
<key>
<column name="IDMEDIA" precision="22" scale="0" not-null="true" />
</key>
<many-to-many entity-name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolReference">
<column name="IDREFERENCE" precision="22" scale="0" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
TespTaxon.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 26-ago-2016 9:41:02 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="es.magrama.iepnb.especies.bom.hibernate.tables.TespTaxon" table="TESP_TAXON" schema="DBA_IEPNB" lazy="true" >
<id name="taxonid" type="big_decimal">
<column name="TAXONID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="tespPliniancoreExtension" class="es.magrama.iepnb.especies.bom.hibernate.tables.TespPliniancoreExtension" lazy="false" fetch="select">
<column name="TAXONRECORDID" precision="22" scale="0" />
</many-to-one>
<set name="tespEolmedias" table="TESP_TAXON_EOL_MEDIA" inverse="false" lazy="false" fetch="select">
<key>
<column name="TAXONID" precision="22" scale="0" not-null="true" />
</key>
<many-to-many entity-name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolmedia">
<column name="IDMEDIA" precision="22" scale="0" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>