[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2914) Hibernate cannot save properties that arae collections of elements of union-subclasses.

Frederico Guimarães (JIRA) noreply at atlassian.com
Thu Oct 25 18:13:38 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28560 ] 

Frederico Guimarães commented on HHH-2914:
------------------------------------------

I could run the aplication declaring a "sql-insert" that invoque a procedure that tries to update all tables from classes that extends from AbstractPerson.
...
update user set idDepartament =? where id=?;
update teacher set idDepartament =? where id=?;
update director set idDepartament =? where id=?;
...

But I don't want to depend on procedures, and  I think that the right thing is the hibernate itself generate the update sql correctly.
My example is not an uncommon example (just in my apllication I have three other examples where the same situation occurs)

> Hibernate cannot save properties that arae collections of elements of union-subclasses.
> ---------------------------------------------------------------------------------------
>
>                 Key: HHH-2914
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2914
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core, query-sql
>    Affects Versions: 3.2.5
>            Reporter: Frederico Guimarães
>            Priority: Critical
>
> I have a class Departament that have a collection of class AbstractPerson:
> 		<bag lazy="true" name="person" cascade="save-update">
> 			<key column="idPerson" />
> 			<one-to-many class="AbstractPerson" />
> 		</bag>
> AbstractPerson is abstract an have a lot os subclasses all of then mapped using union-subclass (none of the abstract classes has a table, all of them are mapped with abstract="true")
> When I do a code like:
> AbstractPerson student = new Student();
> Departament departament = new Departament();
> departament.getPersons().add( student );
> ...
> session.saveOrUpdate( student )
> ...
> I receive the exception:
> org.hibernate.exception.SQLGrammarException: could not insert collection: [br.com.project.model.Departament.persons#29164]
> 	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
> 	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
> 	at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1183)
> 	at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
> 	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
> 	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
> 	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:145)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
> 	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
> 	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
> 	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
> 	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
> 	at br.com.utilities.db.hibernate.AppDBHibernate.execute(AppDBHibernate.java:785)
> 	at br.com.utilities.db.hibernate.AppDBHibernate.execute(AppDBHibernate.java:754)
> 	at br.com.mindsatwork.mopi.importer.Importer.importInspections(Importer.java:733)
> 	at br.com.mindsatwork.mopi.importer.AppMain.main(AppMain.java:120)
> Caused by: java.sql.BatchUpdateException: Base table or view not found message from server: "Table 'project.AbstractPerson' doesn't exist"
> 	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
> 	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
> 	at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
> 	at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1146)
> 	... 13 more
> ...
> if show_sql is active hibernate prints the sql:
> update AbstractPerson set idDepartament =? where id=?
> Why is Hibernate trying to access a table that wat NOT declared and does not exist (as the AbstractPerson is mapped with abstract "true") instead of look for the type of the object (in this case Student) and create a sql with the right table (update user set idDepartament =? where id=?)?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       




More information about the hibernate-issues mailing list