These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: TransactionException: Transaction not successfully started
PostPosted: Wed Jun 25, 2008 10:01 am 
Newbie

Joined: Tue Jan 22, 2008 11:47 am
Posts: 10
I get the following exception during an insert, I think it says I am trying to include two records with the same primary key, but i think it is not true, every primary is different with the others.

Code:
Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started
   at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)
   at com.eliop.diana.model.manager.WsDiasFestivosManager.insertar(WsDiasFestivosManager.java:76)
   at com.eliop.diana.services.ServicioConsultaCalendarioFestivo.invoke(ServicioConsultaCalendarioFestivo.java:43)
   at com.eliop.diana.services.ServiciosTPLWSRecuperacionServiceClient.main(ServiciosTPLWSRecuperacionServiceClient.java:81)


These are the primary keys data, the last one is where it launches the exception:

[code]
2008,1, ,31/12/2007
2008,2, ,30/04/2008
2008,2, ,14/08/2008
[code]

This is the code:

[code]
public void insertar(CalenFesti[] consultaCalendarioFestivoReturn, String anio) {
Session sessionHibernate = HibernateSessionFactory.getSession();
Transaction transaction = sessionHibernate.beginTransaction();

try
{
eliminarAnio(sessionHibernate, anio);
transaction.commit();
for (CalenFesti diaFestivo : consultaCalendarioFestivoReturn) {
insertarDiaFestivo(sessionHibernate, diaFestivo, anio);
}
}
catch (HibernateException e)
{
transaction.rollback();
throw e;
}
}

public void insertarDiaFestivo(Session sessionHibernate, CalenFesti diaFestivo, String anio) {
Transaction transaction = sessionHibernate.beginTransaction();
String codCA = diaFestivo.getCodCA();
String codIsla = diaFestivo.getCodIsla();

Calendar[] fechas = diaFestivo.getFechas();
for (Calendar fecha : fechas) {
WsDiasFestivos wsDiasFestivos = new WsDiasFestivos();
WsDiasFestivosId wsDiasFestivosId = new WsDiasFestivosId();
wsDiasFestivosId.setAnio(anio);
wsDiasFestivosId.setCodCa(Long.valueOf(codCA));
wsDiasFestivosId.setCodIslaComarca(codIsla);
wsDiasFestivosId.setFecha(FechaUtil.getDDbarraMMbarraAAAA(fecha));
System.out.println(wsDiasFestivosId.getAnio()+wsDiasFestivosId.getCodCa().toString()+wsDiasFestivosId.getCodIslaComarca()+wsDiasFestivosId.getFecha());
wsDiasFestivos.setId(wsDiasFestivosId);
wsDiasFestivos.setCodSeq(Long.valueOf(FechaUtil.getAAAAMMDD(fecha)));
wsDiasFestivos.setFechaGbd(new Date());
sessionHibernate.save(wsDiasFestivos);
transaction.commit();
}
}

public void eliminarAnio(Session sessionHibernate, String anio) {
Query q = sessionHibernate.createQuery(
"delete "+
"from WsDiasFestivos "+
"where (anio = ?)");
q.setString(0, anio);
int rows = q.executeUpdate();
}

[/code]

And this is the cfg.xml file:

[code]
<?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">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.eliop.diana.model.WsDiasFestivos" table="WS_DIAS_FESTIVOS" schema="CENTAX">
<composite-id name="id" class="com.eliop.diana.model.WsDiasFestivosId">
<key-property name="anio" type="java.lang.String">
<column name="ANIO" length="4" />
</key-property>
<key-property name="codCa" type="java.lang.Long">
<column name="COD_CA" precision="2" scale="0" />
</key-property>
<key-property name="codIslaComarca" type="java.lang.String">
<column name="COD_ISLA_COMARCA" length="2" />
</key-property>
<key-property name="fecha" type="java.lang.String">
<column name="FECHA" length="40" />
</key-property>
</composite-id>
<property name="codSeq" type="java.lang.Long">
<column name="COD_SEQ" precision="8" scale="0" not-null="true" />
</property>
<property name="fechaGbd" type="java.util.Date">
<column name="FECHA_GBD" length="7" not-null="true" />
</property>
</class>
</hibernate-mapping>
[/code]

Thanks a lot by your help.
Joseba.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.