Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Aggregated objects cannot be written/deleted/queried independently from their owners
Aggregated objects cannot be written/deleted/queried independently from their owners [message #1023931] Mon, 25 March 2013 13:38 Go to next message
Luiz E. is currently offline Luiz E.
Messages: 97
Registered: September 2010
Member
I have a class like this:

    @Entity
    @Indexes(value={
    		@Index(name="idx_produto", columnNames={"codigoInterno"}),
    		@Index(name="idx_produto_ean_com",columnNames={"eanComercial"}),
    		@Index(name="idx_prod_unicidade",columnNames={"codigoInterno","empresa_id"})
    })
    @Customizer(ProdutoCustomizer.class)
    @AggressiveCache
    public class Produto implements Serializable {
    
    	private static final long serialVersionUID = -4801725521366642420L;
    	
    
    	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    	private Long id;
    	
    	@Column(nullable=false, length=14)
    	@NotEmpty(message="É obrigatório um código interno")
    	@Length(max=14, message="O código interno não pode ultrapassar 14 digitos")
    	private String codigoInterno;
    	
    	@Embedded
    	private Combustivel combustivel = new Combustivel();


when I try to "delete" this entity, I got this error:

    Exception [EclipseLink-6002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.QueryException
    Exception Description: Aggregated objects cannot be written/deleted/queried independently from their owners. 
    Descriptor: [RelationalDescriptor(br.com.germantech.ecf.dominio.modelo.produto.Combustivel --> [])]
    Query: DeleteObjectQuery(br.com.germantech.ecf.dominio.modelo.produto.Combustivel@1a7cbdd)


Actually, I do not remove the entity from database. as seen, I have and customizer which just set the product as inactive, like this

    public class ProdutoCustomizer implements DescriptorCustomizer {
    	public void customize(ClassDescriptor descriptor) {
    		descriptor.getQueryManager().setDeleteSQLString("update Produto set ativo = false where id = #ID");
    	}


so, what am I missing here? the `Combustivel` **MUST** be embedded, I can't change that

The stacktrace

    [EL Warning]: 2013-03-21 10:59:34.659--UnitOfWork(12940738)--Thread(Thread[main,6,main])--Local Exception Stack: 
    Exception [EclipseLink-6002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.QueryException
    Exception Description: Aggregated objects cannot be written/deleted/queried independently from their owners. 
    Descriptor: [RelationalDescriptor(br.com.germantech.ecf.dominio.modelo.produto.Combustivel --> [])]
    Query: DeleteObjectQuery(br.com.germantech.ecf.dominio.modelo.produto.Combustivel@d4ca28)
    	at org.eclipse.persistence.exceptions.QueryException.aggregateObjectCannotBeDeletedOrWritten(QueryException.java:240)
    	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.prepare(ObjectLevelModifyQuery.java:205)
    	at org.eclipse.persistence.queries.DeleteObjectQuery.prepare(DeleteObjectQuery.java:327)
    	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:614)
    	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:575)
    	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:820)
    	at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:751)
    	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
    	at org.eclipse.persistence.queries.DeleteObjectQuery.executeInUnitOfWorkObjectLevelModifyQuery(DeleteObjectQuery.java:119)
    	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
    	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2875)
    	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1602)
    	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1584)
    	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1535)
    	at org.eclipse.persistence.queries.DeleteObjectQuery.executeDatabaseQuery(DeleteObjectQuery.java:194)
    	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:852)
    	at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:751)
    	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
    	at org.eclipse.persistence.queries.DeleteObjectQuery.executeInUnitOfWorkObjectLevelModifyQuery(DeleteObjectQuery.java:119)
    	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
    	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2875)
    	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1602)
    	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1584)
    	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1535)
    	at org.eclipse.persistence.internal.sessions.CommitManager.deleteAllObjects(CommitManager.java:334)
    	at org.eclipse.persistence.internal.sessions.CommitManager.deleteAllObjects(CommitManager.java:283)
    	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1422)
    	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:634)
    	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1509)
    	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:266)
    	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1147)
    	at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)
    	at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
    	at br.com.germantech.ecf.aplicacao.interceptors.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
    	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
    	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:52)
    	at br.com.germantech.ecf.infraestrutura.persistencia.repositorios.ProdutoRepositoryImpl$$EnhancerByGuice$$d68cdfa4.delete(<generated>)
    	at br.com.germantech.ecf.infraestrutura.persistencia.repositorios.ProdutoRepositoryImpl.delete(ProdutoRepositoryImpl.java:1)
    	at br.com.germantech.ecf.aplicacao.services.ProdutoService.delete(ProdutoService.java:66)
    	at br.com.germantech.ecf.telas.editors.ProdutoEditor.excluirRegistro(ProdutoEditor.java:231)
    	at br.com.germantech.ecf.telas.editors.GermantechEditor$2.widgetSelected(GermantechEditor.java:108)
    	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
    	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
    	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
    	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
    	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
    	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
    	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    	at br.com.germantech.ecf.aplicacao.internal.Application.start(Application.java:39)
    	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Re: Aggregated objects cannot be written/deleted/queried independently from their owners [message #1027060 is a reply to message #1023931] Tue, 26 March 2013 14:10 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Ensure you don't call remove() on the embeddable.

Include the mappings for Combustivel, and try removing your customizers/events.


James : Wiki : Book : Blog : Twitter
Re: Aggregated objects cannot be written/deleted/queried independently from their owners [message #1027077 is a reply to message #1027060] Tue, 26 March 2013 14:26 Go to previous message
Luiz E. is currently offline Luiz E.
Messages: 97
Registered: September 2010
Member
I saw a @ManyToOne relation on Combustivel
Just removed this relation and worked fine, thank you
Previous Topic:validate unique column before commit
Next Topic:Custom Insert/Update/Delete (Virsioning)
Goto Forum:
  


Current Time: Fri Oct 24 13:33:05 GMT 2014

Powered by FUDForum. Page generated in 0.04510 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software