-->
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: EmbeddedId leads to foreign key constraint on delete
PostPosted: Tue Mar 19, 2013 2:57 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I'm running into a kind of edge case.
I have an entity
Code:

Network
         @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY, mappedBy="network")
         @Fetch(FetchMode.SUBSELECT)
         @BatchSize(size=25)
         @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.NETWORK)
         Set<NetworkUser> users;

NetworkUser
        @EmbeddedId
        @DocumentId(name="id")
   @FieldBridge(impl = NetworkUserIdBridge.class)
        NetworkUserId;

   @MapsId(value = "networkId")
   @ManyToOne(fetch=FetchType.LAZY,optional=false)
   @JoinColumn(name="networkId",referencedColumnName="networkId",nullable=false,updatable=false)
   @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,region=CacheRegion.NETWORK)
   @IndexedEmbedded(includePaths={"id"})
   private Network;

   @MapsId(value = "userId")
   @ManyToOne(fetch=FetchType.LAZY,optional=false)
   @JoinColumn(name="userId",referencedColumnName="userId",nullable=false,updatable=false)
   @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,region=CacheRegion.USER)
   @IndexedEmbedded(includePaths={"id"})
   private Usor;

@Embeddable
NetworkUserId
        @Column(insertable = false, updatable = false)
   private Long networkId;

        @Column(insertable = false, updatable = false)
        private Long userId;


Whenever I delete a Network, the cascade delete for NetworkUser generates an exception when I have @IndexedEmbedded on
private Usor;

Without the @IndexedEmbedded, I don't get the exception.

Code:

org.hibernate.exception.ConstraintViolationException: integrity constraint violation: foreign key no action; FK9F3B077BBBAA398 table: NETWORK_USERS
   at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:74)
   at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
   at com.sun.proxy.$Proxy161.executeUpdate(Unknown Source)
   at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3306)
   at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3506)
   at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:100)
   at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
   at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
   at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:280)
   at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
   at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
   at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213)
   at org.appfuse.dao.hibernate.GenericDaoHibernate.flush(GenericDaoHibernate.java:165)
   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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
   at com.sun.proxy.$Proxy145.flush(Unknown Source)
   at org.appfuse.service.impl.GenericManagerImpl.clearSession(GenericManagerImpl.java:180)
   at nl.project.service.WallManagerTest.teardown(WallManagerTest.java:125)
   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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
   at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
   at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
   at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
   at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
   at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
   at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
   at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: foreign key no action; FK9F3B077BBBAA398 table: NETWORK_USERS
   at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
   at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
   at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
   at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
   at com.jolbox.bonecp.PreparedStatementHandle.executeUpdate(PreparedStatementHandle.java:203)
   at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
   ... 48 more
Caused by: org.hsqldb.HsqlException: integrity constraint violation: foreign key no action; FK9F3B077BBBAA398 table: NETWORK_USERS
   at org.hsqldb.error.Error.error(Unknown Source)
   at org.hsqldb.StatementDML.performReferentialActions(Unknown Source)
   at org.hsqldb.StatementDML.delete(Unknown Source)
   at org.hsqldb.StatementDML.executeDeleteStatement(Unknown Source)
   at org.hsqldb.StatementDML.getResult(Unknown Source)
   at org.hsqldb.StatementDMQL.execute(Unknown Source)
   at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
   at org.hsqldb.Session.execute(Unknown Source)
   ... 55 more



Any suggestions?

Kind regards,
Marc


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.