0

I have problems when try insert into BBDD an object. I copy my code here, sorry for my English.

Code when I build the object:

generaAvisoCups(new TControlDispatchCupsDay(gasDay, "DIARIA", tMaiCups, qd, 
                    telem, false, tTypeSolution, new Date(), new Date()));



@Entity
@Table(name = "t_control_dispatch_cups_day")
public class TControlDispatchCupsDay implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = -2612331133209150754L;

private int id;
private TMaiCups TMaiCups;
private TTypeSolution TTypeSolution;
private Date gasDay;
private BigDecimal limit;
private BigDecimal energy;
private boolean checked;
private Date creationDate;
private Date modificationDate;
private String chain;

public TControlDispatchCupsDay() {
}

public TControlDispatchCupsDay(Date gasDay, String chain,
        TMaiCups TMaiCups, BigDecimal limit, BigDecimal energy, boolean checked,
        TTypeSolution TTypeSolution, Date creationDate, Date modificationDate) {
    this.gasDay = gasDay;
    this.TMaiCups = TMaiCups;
    this.TTypeSolution = TTypeSolution;
    this.limit = limit;
    this.energy = energy;
    this.checked = checked;
    this.creationDate = creationDate;
    this.modificationDate = modificationDate;
    this.chain = chain;
}

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="t_control_dispatch_cups_day_seq")
@SequenceGenerator(name="t_control_dispatch_cups_day_seq", sequenceName="t_control_dispatch_cups_day_seq", allocationSize=1)
@Column(name = "id", unique = true, nullable = false)
public int getId() {
    return this.id;
}

public void setId(int id) {
    this.id = id;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cups",referencedColumnName = "cups")
public TMaiCups getTMaiCups() {
    return this.TMaiCups;
}

public void setTMaiCups(TMaiCups TMaiCups) {
    this.TMaiCups = TMaiCups;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "solution", nullable = false, referencedColumnName = "type")
public TTypeSolution getTTypeSolution() {
    return this.TTypeSolution;
}

public void setTTypeSolution(TTypeSolution TTypeSolution) {
    this.TTypeSolution = TTypeSolution;
}

@Temporal(TemporalType.DATE)
@Column(name = "gas_day", nullable = false, length = 13)
public Date getGasDay() {
    return this.gasDay;
}

public void setGasDay(Date gasDay) {
    this.gasDay = gasDay;
}

@Column(name = "limite")
public BigDecimal getLimit() {
    return this.limit;
}

public void setLimit(BigDecimal limit) {
    this.limit = limit;
}

@Column(name = "energy")
public BigDecimal getEnergy() {
    return this.energy;
}

public void setEnergy(BigDecimal energy) {
    this.energy = energy;
}

@Column(name = "checked")
@Type(type="true_false")
public boolean getChecked() {
    return this.checked;
}

public void setChecked(boolean checked) {
    this.checked = checked;
}

@Column(name = "creation_date", nullable = false, length = 29)
public Date getCreationDate() {
    return this.creationDate;
}

public void setCreationDate(Date creationDate) {
    this.creationDate = creationDate;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modification_date", nullable = false, length = 29)
public Date getModificationDate() {
    return this.modificationDate;
}

public void setModificationDate(Date modificationDate) {
    this.modificationDate = modificationDate;
}

@Column(name = "cadena", nullable = false, length = 10)
public String getChain() {
    return this.chain;
}

public void setChain(String chain) {
    this.chain = chain;
}

}

@SuppressWarnings("rawtypes")
@Transactional
public class BaseDaoImpl extends HibernateDaoSupport implements Serializable {

...............
.............
............

    protected void save(Object transientInstance) throws Exception {
        try {
            getHibernateTemplate().getSessionFactory().getCurrentSession().save(transientInstance);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new Exception("Error al guardar el elemento.", e);
        }
    }


............
}

PostgreSQL

CREATE TABLE t_control_dispatch_cups_day
(
  gas_day date NOT NULL,
  energy numeric,
  checked boolean,
  creation_date timestamp without time zone NOT NULL DEFAULT now(),
  modification_date timestamp without time zone NOT NULL DEFAULT now(),
  cadena character varying(10) NOT NULL,
  solution character varying(1) NOT NULL,
  cups character varying(20) NOT NULL,
  id integer NOT NULL DEFAULT nextval('t_control_dispatch_cups_day_seq'::regclass),
  limite numeric,
  CONSTRAINT "table_PKs" PRIMARY KEY (id),
  CONSTRAINT "FK_cups" FOREIGN KEY (cups)
      REFERENCES t_mai_cups (cups) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "FK_solution" FOREIGN KEY (solution)
      REFERENCES t_type_solution (type) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);
org.springframework.dao.InvalidDataAccessResourceUsageException: Could not execute JDBC batch update; SQL [insert into t_control_dispatch_cups_day (cups, solution, cadena, checked, creation_date, energy, gas_day, limite, modification_date, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
        at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at com.sun.proxy.$Proxy124.addNotificationCupsImpl(Unknown Source)
        at com.aia.processor.daily.dispatcher.DailyDispatcherProcess.generaAvisoCups(DailyDispatcherProcess.java:1355)
        at com.aia.processor.daily.dispatcher.DailyDispatcherProcess.checkQdDobleForCups(DailyDispatcherProcess.java:1606)
        at com.aia.processor.daily.dispatcher.DailyDispatcherProcess.saveDispNetDayCups(DailyDispatcherProcess.java:1496)
        at com.aia.processor.daily.dispatcher.DailyDispatcherProcess.saveData(DailyDispatcherProcess.java:1340)
        at com.aia.processor.daily.dispatcher.DailyDispatcherProcess.doDispatch(DailyDispatcherProcess.java:466)
        at com.aia.processor.daily.dispatcher.DailyDispatcherProcess.execute(DailyDispatcherProcess.java:277)
        at com.aia.mrg.web.ctl.daily.DailyDispatchCtl.recalcularReparto(DailyDispatchCtl.java:218)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
        at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
        at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:772)
        at javax.faces.component.UICommand.broadcast(UICommand.java:300)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
        ... 77 more
    Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into t_control_dispatch_cups_day (cups, solution, cadena, checked, creation_date, energy, gas_day, limite, modification_date, id) values ('ES0217901000013299MP', 'P', 'DIARIA', 'F', '2016-03-30 08:05:05.983000 +02:00:00', '22293', '2014-03-12 +01:00:00', '55900.000000000000000', '2016-03-30 08:05:05.984000 +02:00:00', '34') was aborted.  Call getNextException to see the cause.
        at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2621)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1837)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2754)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
        ... 85 more
5
  • 1
    can you please post the stacktrace? Commented Mar 29, 2016 at 16:36
  • Ok, sorry I forgot this part. Commented Mar 30, 2016 at 6:10
  • "Call getNextException to see the cause" - what do you get when you do that? But if I have to guess, I would say you are inserting something that is already there Commented Mar 30, 2016 at 6:15
  • I have done getNextException and the problem was the boolean variable "checked". I have erased this line "@Type(type="true_false")" because was trying to save an varying instead of boolean. Now, I can save the object in BBDD with "getHibernateTemplate().save(object);", I can't save with "getHibernateTemplate().getSessionFactory().getCurrentSession().save(object);" because say "org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started". Thankss!! Commented Mar 30, 2016 at 8:53
  • With new changes you made, your problem could be the same as the discused in this question: stackoverflow.com/questions/7484890/… Commented Mar 31, 2016 at 23:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.