-->
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: Problems with inheritance.
PostPosted: Sun Sep 18, 2005 5:00 pm 
Newbie

Joined: Sun Sep 18, 2005 4:48 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.smallsquid.eGA.model.other.Contenido" table="contenido" select-before-update="false" dynamic-update="false" dynamic-insert="false" optimistic-lock="version">
<id name="idcontenido" column="idContenido" type="java.lang.Integer">
<generator class="increment">
</generator>
</id>
<property name="descripcion" type="java.lang.String" update="true" insert="true" access="property" column="descripcion" not-null="false" unique="false"/>
<!-- exported bi-directional many-to-one association to Bibliografia -->
<many-to-one name="Bibliografia" class="com.smallsquid.eGA.model.other.Bibliografia" not-null="false" outer-join="auto" insert="false" update="false">
<column name="idContenido"/>
</many-to-one>
<!-- exported bi-directional many-to-one association to Capacidadesprevias -->
<many-to-one name="Capacidadesprevias" class="com.smallsquid.eGA.model.other.Capacidadesprevias" not-null="false" outer-join="auto" insert="false" update="false">
<column name="idContenido"/>
</many-to-one>
<!-- exported bi-directional one-to-many association to Descripciones -->
<set name="descripcionesGroup" table="descripciones" lazy="true" inverse="true" cascade="save-update" sort="unsorted">
<key>
<column name="idContenido"/>
</key>
<one-to-many class="com.smallsquid.eGA.model.other.Descripciones"/>
</set>
<!-- exported bi-directional many-to-one association to Enlaces -->
<many-to-one name="Enlaces" class="com.smallsquid.eGA.model.other.Enlaces" not-null="false" outer-join="auto" insert="false" update="false">
<column name="idContenido"/>
</many-to-one>
<!-- exported bi-directional many-to-one association to Metodoevaluacion -->
<many-to-one name="Metodoevaluacion" class="com.smallsquid.eGA.model.other.Metodoevaluacion" not-null="false" outer-join="auto" insert="false" update="false">
<column name="idContenido"/>
</many-to-one>
<many-to-one name="Tarea" class="com.smallsquid.eGA.model.other.Tarea" not-null="false" outer-join="auto" insert="false" update="false">
<column name="idContenido"/>
</many-to-one>
<!-- exported bi-directional many-to-one association to Temario -->
<many-to-one name="Temario" class="com.smallsquid.eGA.model.other.Temario" not-null="false" outer-join="auto" insert="false" update="false">
<column name="idContenido"/>
</many-to-one>

<!-- exported bi-directional many-to-one association to Objetivos -->
<joined-subclass name="com.smallsquid.eGA.model.other.Objetivos" table="objetivos" extends="com.smallsquid.eGA.model.other.Contenido"
dynamic-insert="true"
dynamic-update="false">
<key column="Contenido_idContenido"/>
<property name="objetivo" type="java.lang.String" update="true" insert="true" access="property" column="objetivo" length="65535" not-null="false" unique="false"/>
<!-- imported bi-directional many-to-one association to Contenido -->
<many-to-one name="Contenido" class="com.smallsquid.eGA.model.other.Contenido" not-null="false" update="false" insert="false">
<column name="Contenido_idContenido"/>
</many-to-one>
<!-- imported bi-directional many-to-one association to Cuatrimestre -->
<many-to-one name="Cuatrimestre" class="com.smallsquid.eGA.model.other.Cuatrimestre" not-null="false" outer-join="auto" insert="false" update="false">
<column name="Cuatrimestre_anyo"/>
<column name="Cuatrimestre_num"/>
</many-to-one>
<!-- exported bi-directional many-to-one association to Objetivosespecificos -->
<!--many-to-one name="Objetivosespecificos" class="com.smallsquid.eGA.model.other.Objetivosespecificos" not-null="false" outer-join="auto" insert="false" update="false">
<column name="Contenido_idContenido"/>
</many-to-one-->
<joined-subclass name="com.smallsquid.eGA.model.other.Objetivosespecificos" table="objetivosespecificos"
extends="com.smallsquid.eGA.model.other.Objetivos">
<key column="Objetivos_Contenido_idContenido"/>
</joined-subclass>
<!-- exported bi-directional many-to-one association to Objetivosgenerales -->
<joined-subclass name="com.smallsquid.eGA.model.other.Objetivosgenerales" table="objetivosgenerales"
extends="com.smallsquid.eGA.model.other.Objetivos">
<key column="Objetivos_Contenido_idContenido"/>
</joined-subclass>
</joined-subclass>
<!--many-to-one name="Objetivos" class="com.smallsquid.eGA.model.other.Objetivos" not-null="false" outer-join="auto" insert="false" update="false">
<column name="idContenido"/>
</many-to-one-->
<!-- exported bi-directional many-to-one association to Tarea -->
</class>
</hibernate-mapping>



Database tables:
CREATE TABLE Contenido (
idContenido INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(idContenido)
)
TYPE=InnoDB;

CREATE TABLE Objetivos (
Contenido_idContenido INTEGER UNSIGNED NOT NULL,
Cuatrimestre_num INTEGER UNSIGNED NOT NULL,
Cuatrimestre_anyo INTEGER UNSIGNED NOT NULL,
objetivo TEXT NULL,
PRIMARY KEY(Contenido_idContenido),
INDEX Objetivos_FKIndex1(Contenido_idContenido),
INDEX Objetivos_FKIndex2(Cuatrimestre_anyo, Cuatrimestre_num),
FOREIGN KEY(Contenido_idContenido)
REFERENCES Contenido(idContenido)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY(Cuatrimestre_anyo, Cuatrimestre_num)
REFERENCES Cuatrimestre(anyo, num)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
TYPE=InnoDB;
CREATE TABLE ObjetivosEspecificos (
Objetivos_Contenido_idContenido INTEGER UNSIGNED NOT NULL,
PRIMARY KEY(Objetivos_Contenido_idContenido),
INDEX ObjetivosEspecificos_FKIndex1(Objetivos_Contenido_idContenido),
FOREIGN KEY(Objetivos_Contenido_idContenido)
REFERENCES Objetivos(Contenido_idContenido)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
TYPE=InnoDB;

CREATE TABLE ObjetivosGenerales (
Objetivos_Contenido_idContenido INTEGER UNSIGNED NOT NULL,
PRIMARY KEY(Objetivos_Contenido_idContenido),
INDEX ObjetivosGenerales_FKIndex1(Objetivos_Contenido_idContenido),
FOREIGN KEY(Objetivos_Contenido_idContenido)
REFERENCES Objetivos(Contenido_idContenido)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
TYPE=InnoDB;


I want to save an object of ObjetivosGenerales, which inhrit from Objetivos, and this inherit from Contenido.

I have the next code to save an instance of ObjetivosGenerales:

ObjetivosgeneralesForm objetivosgeneralesForm = (ObjetivosgeneralesForm) form;
Objetivosgenerales objetivosgenerales = getObjetivosgeneralesFromForm(form);
boolean isNew = objetivosgenerales.getIdcontenido() == null ;
ObjetivosgeneralesManager mgr = (ObjetivosgeneralesManager) getBean("objetivosgeneralesManager");
Objetivos objetivo = null;
if (isNew){
CuatrimestreactualManager caMgr = (CuatrimestreactualManager)getBean("cuatrimestreactualManager");
Cuatrimestreactual cuatrimestreactual = caMgr.getCuatrimestreactual(new Integer(1));
objetivosgenerales.setCuatrimestre(cuatrimestreactual.getCuatrimestre());
objetivosgenerales.setCuatrimestreAnyo(cuatrimestreactual.getCuatrimestreAnyo());
objetivosgenerales.setCuatrimestreNum(cuatrimestreactual.getCuatrimestreNum());
}else{
objetivosgenerales = mgr.getObjetivosgenerales(objetivosgenerales.getIdcontenido());
}
objetivosgenerales.setObjetivo(objetivosgeneralesForm.getObjetivo());
try {
mgr.saveObjetivosgenerales(objetivosgenerales);



But when i try to save it return me the next exception


[eGA] DEBUG [http-8080-Processor125] ObjetivosDAOHibernate.saveObjetivos(49) | objetivos's id: null
Hibernate: insert into contenido (idContenido) values (?)
Hibernate: insert into objetivos (objetivo, Contenido_idContenido) values (?, ?)
[eGA] WARN [http-8080-Processor125] JDBCExceptionReporter.logExceptions(71) | SQL Error: 1216, SQLState: 23000
[eGA] ERROR [http-8080-Processor125] JDBCExceptionReporter.logExceptions(72) | Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"
[eGA] ERROR [http-8080-Processor125] AbstractFlushingEventListener.performExecutions(277) | Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [com.smallsquid.eGA.model.other.Objetivosgenerales]
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1859)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2184)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:309)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:484)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:401)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:67)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy44.saveObjetivos(Unknown Source)
at com.smallsquid.eGA.webapp.action.other.ObjetivosAction.save(ObjetivosAction.java:192)
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:324)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
at com.smallsquid.eGA.webapp.action.BaseAction.execute(BaseAction.java:221)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.smallsquid.eGA.webapp.filter.GZIPFilter.doFilter(GZIPFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.opensymphony.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.smallsquid.eGA.webapp.filter.ActionFilter.doFilter(ActionFilter.java:122)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
at net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:84)
at net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:182)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:153)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.wrapper.ContextHolderAwareRequestFilter.doFilter(ContextHolderAwareRequestFilter.java:50)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:225)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:305)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1772)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1619)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1846)
... 95 more
[eGA] WARN [http-8080-Processor125] ObjetivosgeneralesAction.save(194) | Objetivos already exists: (HibernateTemplate): data integrity violated by SQL ''; nested exception is java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"


Could somebody help me?
Thanks
Full stack trace of any exception that occurs:

Name and version of the database you are using:4.17

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


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.