-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cannot delete from many-to-many with intermediate entity
PostPosted: Thu Jan 15, 2009 8:12 pm 
Newbie

Joined: Thu Jan 15, 2009 7:27 pm
Posts: 4
Location: Boulder, CO
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I have a program that has application objects, and each application is both a client and a server(resource).

I implemented the many-to-many relationship between applications with an intermediate table: resource.

I followed the example on page 304 of "Java persistence with hibernate".

Every application has a set of clients (when it acts like a server), and a set of resources (when it acts like a client).

I can *not* delete an application from the system that has a set of resources for some reason. I've tried cascade.delete, cascade.delete_orphan, cascade.all, etc.

clientApp.resources(set) <--> resource <--> resourceApp.clients(set)

I've tried many different configurations for days, and nothing seems to work.

I don't know why hibernate is trying to update the resource table, instead of just deleting the row.

Thanks,
-Christoph.

Hibernate version:

3.0

Mapping documents:

@Entity
@Table(schema="foo", name="APPLICATION")
public class Application {

...
@OneToMany
@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@JoinColumn(name="client_application_id")
public Set<Resource> getResources() {
return this.resources;
}
public void setResources(Set<Resource> resources) {
this.resources = resources;
}

@OneToMany
@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@JoinColumn(name="resource_application_id")
public Set<Resource> getClients() {
return this.clients;
}
public void setClients(Set<Resource> clients) {
this.clients = clients;
}
...
}

@Entity
@Table(schema="foo", name="RESOURCE")
public class Resource {

@Embeddable
public static class Id implements Serializable {
@Column(name="client_application_id")
private Long clientApplicationId;
@Column(name="resource_application_id")
private Long resourceApplicationId;

public Id() {}

public Id(Long clientApplicationId, Long resourceApplicationId) {
this.clientApplicationId = clientApplicationId;
this.resourceApplicationId = resourceApplicationId;
}

public boolean equals(Object o) {
if (o != null && o instanceof Id) {
Id that = (Id)o;
return this.clientApplicationId.equals(that.clientApplicationId) &&
this.resourceApplicationId.equals(that.resourceApplicationId);
} else {
return false;
}
}

public int hashCode() {
return clientApplicationId.hashCode() + resourceApplicationId.hashCode();
}
}

@EmbeddedId
private Id id = new Id();

@ManyToOne
@JoinColumn(name="client_application_id", insertable=false, updatable=false)
private Application clientApplication;

@ManyToOne
@JoinColumn(name="resource_application_id", insertable=false, updatable=false)
private Application resourceApplication;

public Resource() {
}

public Resource(Application clientApplication, Application resourceApplication) {
this.clientApplication = clientApplication;
this.resourceApplication = resourceApplication;

this.id.clientApplicationId = clientApplication.getId();
this.id.resourceApplicationId = resourceApplication.getId();

// Guarantee referential integrity.
clientApplication.getResources().add(this);
resourceApplication.getClients().add(this);

}
...
}

Code between sessionFactory.openSession() and session.close():

public ServerpoolApplicationResource(Context context, Request request, Response response) {
super(context, request, response);

serverpoolName = (String) getRequest().getAttributes().get("serverpool_name");
applicationName = (String) getRequest().getAttributes().get("application_name");

session = ServerpoolApplication.getSessionFactory().getCurrentSession();

try {
tx = session.beginTransaction();
if (serverpoolName != null) {
// Get the serverpool directly from the "persistence layer".
this.serverpool = ServerpoolManager.instance().getServerpoolByName(serverpoolName);
}
if (serverpool != null) {
this.application = ApplicationManager.instance().getApplicationByApplicationNameServerpoolId(applicationName, serverpool.getId());
}
} catch (Exception e) {
ServerpoolLogger.getInstance().error(e);
if (tx != null) tx.rollback();
} finally {
}

// Define the supported variant.
getVariants().add(new Variant(MediaType.TEXT_XML));

}

@Override
public void delete() {

if (!DefaultResource.authenticate(getRequest())) {
if (tx != null) tx.rollback();
getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED, getRequest().getProtocol().getDescription());
return;
}

try {
if (serverpool != null && application != null) {
// Remove the serverpool from the database.
serverpool.getApplications().remove(application);
application.setServerpool(null);
ApplicationManager.instance().deleteApplication(application);

DomRepresentation rep = application.domRepresentation();
rep.setIdentifier(getRequest().getResourceRef().getIdentifier() + "/" + serverpool.getName());
getResponse().setEntity(rep);
}
tx.commit();
} catch (Exception e) {
ServerpoolLogger.getInstance().error(e);
if (tx != null) tx.rollback();
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return;
} finally {
}

// Tells the client that the request has been successfully fulfilled.
getResponse().setStatus(Status.SUCCESS_OK);
}

public void deleteApplication(Application application) throws Exception {
Session session = ServerpoolApplication.getSessionFactory().getCurrentSession();
try {
assert(application != null);
if (application == null) return;

if (application.getId() != null) {
Application theApplication = (Application) session.get(Application.class, application.getId());
for (Resource resource : theApplication.getResources()) {
resource.getClientApplication().getResources().remove(resource);
resource.getResourceApplication().getClients().remove(resource);
resource.setClientApplication(null);
resource.setResourceApplication(null);
ResourceManager.instance().deleteResource(resource);
}
for (Resource client : theApplication.getClients()) {
client.getClientApplication().getResources().remove(client);
client.getResourceApplication().getClients().remove(client);
client.setClientApplication(null);
client.setResourceApplication(null);
ResourceManager.instance().deleteResource(client);
}
session.delete(theApplication);
}
} catch (Exception e) {
ServerpoolLogger.getInstance().error(e);
throw new Exception(e);
}
session.flush();
}

public void deleteResource(Resource resource) throws Exception {
Session session = ServerpoolApplication.getSessionFactory().getCurrentSession();
try {
assert(resource != null);
if (resource == null) return;

if (resource.getId() != null) {
Resource theResource = (Resource) session.get(Resource.class, resource.getId());
session.delete(theResource);
}
} catch (Exception e) {
ServerpoolLogger.getInstance().error(e);
throw new Exception(e);
}
session.flush();
}


Full stack trace of any exception that occurs:

15:51:15,533 DEBUG AbstractCollectionPersister:1010 - Deleting collection: [jdpa.mlg.serverpool.domain.Serverpool.applications#2]
15:51:15,533 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15:51:15,548 DEBUG SQL:401 - update serverpool.APPLICATION set serverpool_id=null where serverpool_id=?
Hibernate: update serverpool.APPLICATION set serverpool_id=null where serverpool_id=?
15:51:15,548 DEBUG AbstractBatcher:484 - preparing statement
15:51:15,564 DEBUG LongType:133 - binding '2' to parameter: 1
15:51:15,564 DEBUG AbstractCollectionPersister:1067 - done deleting collection
15:51:15,580 DEBUG AbstractCollectionPersister:1204 - Deleting rows of collection: [jdpa.mlg.serverpool.domain.Application.resources#3]
15:51:15,580 DEBUG AbstractBatcher:44 - Executing batch size: 1
15:51:15,751 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
15:51:15,751 DEBUG AbstractBatcher:533 - closing statement
15:51:15,751 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15:51:15,767 DEBUG SQL:401 - update serverpool.RESOURCE set client_application_id=null where client_application_id=? and client_application_id=? and resource_application_id=?
Hibernate: update serverpool.RESOURCE set client_application_id=null where client_application_id=? and client_application_id=? and resource_application_id=?
15:51:15,767 DEBUG AbstractBatcher:484 - preparing statement
15:51:15,783 DEBUG LongType:133 - binding '3' to parameter: 1
15:51:15,783 DEBUG LongType:133 - binding '3' to parameter: 2
15:51:15,783 DEBUG LongType:133 - binding '1' to parameter: 3
15:51:15,798 DEBUG AbstractCollectionPersister:1281 - done deleting collection rows: 1 deleted
15:51:15,798 DEBUG AbstractCollectionPersister:1313 - Inserting rows of collection: [jdpa.mlg.serverpool.domain.Application.resources#3]
15:51:15,798 DEBUG AbstractCollectionPersister:1390 - done inserting rows: 0 inserted
15:51:15,814 DEBUG AbstractCollectionPersister:1010 - Deleting collection: [jdpa.mlg.serverpool.domain.Application.clients#1]
15:51:15,814 DEBUG AbstractBatcher:44 - Executing batch size: 1
15:51:16,001 DEBUG NewPooledConnection:430 - com.mchange.v2.c3p0.impl.NewPooledConnection@3e4a4 handling a throwable.
java.sql.BatchUpdateException: Data truncation: Column set to default value; NULL supplied to NOT NULL column 'client_application_id' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1030)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
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 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.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy14.flush(Unknown Source)
at jdpa.mlg.serverpool.manager.ResourceManager.deleteResource(ResourceManager.java:146)
at jdpa.mlg.serverpool.manager.ApplicationManager.deleteApplication(ApplicationManager.java:150)
at jdpa.mlg.serverpool.resource.ServerpoolApplicationResource.delete(ServerpoolApplicationResource.java:115)
at org.restlet.resource.Resource.handleDelete(Resource.java:369)
at org.restlet.Finder.handle(Finder.java:301)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:89)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:98)
at org.restlet.Application.handle(Application.java:294)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:120)
at org.restlet.Component.handle(Component.java:231)
at org.restlet.Server.handle(Server.java:282)
at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:100)
at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:94)
at com.noelios.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:399)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)
15:51:16,033 DEBUG SqlUtils:85 - Attempted to convert SQLException to SQLException. Leaving it alone. [SQLState: 22001; errorCode: 0]
java.sql.BatchUpdateException: Data truncation: Column set to default value; NULL supplied to NOT NULL column 'client_application_id' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1030)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
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 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.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy14.flush(Unknown Source)
at jdpa.mlg.serverpool.manager.ResourceManager.deleteResource(ResourceManager.java:146)
at jdpa.mlg.serverpool.manager.ApplicationManager.deleteApplication(ApplicationManager.java:150)
at jdpa.mlg.serverpool.resource.ServerpoolApplicationResource.delete(ServerpoolApplicationResource.java:115)
at org.restlet.resource.Resource.handleDelete(Resource.java:369)
at org.restlet.Finder.handle(Finder.java:301)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:89)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:98)
at org.restlet.Application.handle(Application.java:294)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:120)
at org.restlet.Component.handle(Component.java:231)
at org.restlet.Server.handle(Server.java:282)
at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:100)
at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:94)
at com.noelios.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:399)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)
15:51:16,064 DEBUG DefaultConnectionTester:126 - Testing a Connection in response to an Exception:
java.sql.BatchUpdateException: Data truncation: Column set to default value; NULL supplied to NOT NULL column 'client_application_id' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1030)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
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 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.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy14.flush(Unknown Source)
at jdpa.mlg.serverpool.manager.ResourceManager.deleteResource(ResourceManager.java:146)
at jdpa.mlg.serverpool.manager.ApplicationManager.deleteApplication(ApplicationManager.java:150)
at jdpa.mlg.serverpool.resource.ServerpoolApplicationResource.delete(ServerpoolApplicationResource.java:115)
at org.restlet.resource.Resource.handleDelete(Resource.java:369)
at org.restlet.Finder.handle(Finder.java:301)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:89)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:98)
at org.restlet.Application.handle(Application.java:294)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:120)
at org.restlet.Component.handle(Component.java:231)
at org.restlet.Server.handle(Server.java:282)
at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:100)
at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:94)
at com.noelios.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:399)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)
15:51:16,251 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
15:51:16,267 DEBUG AbstractBatcher:533 - closing statement
15:51:16,267 DEBUG JDBCExceptionReporter:69 - Could not execute JDBC batch update [update serverpool.RESOURCE set client_application_id=null where client_application_id=? and clien
t_application_id=? and resource_application_id=?]
java.sql.BatchUpdateException: Data truncation: Column set to default value; NULL supplied to NOT NULL column 'client_application_id' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1030)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
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 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.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy14.flush(Unknown Source)
at jdpa.mlg.serverpool.manager.ResourceManager.deleteResource(ResourceManager.java:146)
at jdpa.mlg.serverpool.manager.ApplicationManager.deleteApplication(ApplicationManager.java:150)
at jdpa.mlg.serverpool.resource.ServerpoolApplicationResource.delete(ServerpoolApplicationResource.java:115)
at org.restlet.resource.Resource.handleDelete(Resource.java:369)
at org.restlet.Finder.handle(Finder.java:301)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:89)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:98)
at org.restlet.Application.handle(Application.java:294)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:120)
at org.restlet.Component.handle(Component.java:231)
at org.restlet.Server.handle(Server.java:282)
at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:100)
at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:94)
at com.noelios.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:399)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)
15:51:16,298 WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 22001
15:51:16,298 ERROR JDBCExceptionReporter:78 - Data truncation: Column set to default value; NULL supplied to NOT NULL column 'client_application_id' at row 1
15:51:16,314 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1030)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
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 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.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy14.flush(Unknown Source)
at jdpa.mlg.serverpool.manager.ResourceManager.deleteResource(ResourceManager.java:146)
at jdpa.mlg.serverpool.manager.ApplicationManager.deleteApplication(ApplicationManager.java:150)
at jdpa.mlg.serverpool.resource.ServerpoolApplicationResource.delete(ServerpoolApplicationResource.java:115)
at org.restlet.resource.Resource.handleDelete(Resource.java:369)
at org.restlet.Finder.handle(Finder.java:301)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:89)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:98)
at org.restlet.Application.handle(Application.java:294)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at org.restlet.Router.handle(Router.java:445)
at org.restlet.Filter.doHandle(Filter.java:105)
at org.restlet.Filter.handle(Filter.java:135)
at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:120)
at org.restlet.Component.handle(Component.java:231)
at org.restlet.Server.handle(Server.java:282)
at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:100)
at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:94)
at com.noelios.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:399)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.BatchUpdateException: Data truncation: Column set to default value; NULL supplied to NOT NULL column 'client_application_id' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 63 more
Name and version of the database you are using:

MySql 5.0

The generated SQL (show_sql=true):

17:04:41,661 DEBUG SQL:401 - update serverpool.RESOURCE set client_application_id=null where client_application_id=? and client_application_id=? and resource_application_id=?
Hibernate: update serverpool.RESOURCE set client_application_id=null where client_application_id=? and client_application_id=? and resource_application_id=?

Debug level Hibernate log excerpt:

17:04:41,489 DEBUG AbstractCollectionPersister:1010 - Deleting collection: [jdpa.mlg.serverpool.domain.Serverpool.applications#2]
17:04:41,489 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
17:04:41,489 DEBUG SQL:401 - update serverpool.APPLICATION set serverpool_id=null where serverpool_id=?
Hibernate: update serverpool.APPLICATION set serverpool_id=null where serverpool_id=?
17:04:41,489 DEBUG AbstractBatcher:484 - preparing statement
17:04:41,489 DEBUG LongType:133 - binding '2' to parameter: 1
17:04:41,489 DEBUG AbstractCollectionPersister:1067 - done deleting collection
17:04:41,489 DEBUG AbstractCollectionPersister:1204 - Deleting rows of collection: [jdpa.mlg.serverpool.domain.Application.resources#3]
17:04:41,489 DEBUG AbstractBatcher:44 - Executing batch size: 1
17:04:41,661 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
17:04:41,661 DEBUG AbstractBatcher:533 - closing statement
17:04:41,661 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
17:04:41,661 DEBUG SQL:401 - update serverpool.RESOURCE set client_application_id=null where client_application_id=? and client_application_id=? and resource_application_id=?
Hibernate: update serverpool.RESOURCE set client_application_id=null where client_application_id=? and client_application_id=? and resource_application_id=?
17:04:41,661 DEBUG AbstractBatcher:484 - preparing statement
17:04:41,661 DEBUG LongType:133 - binding '3' to parameter: 1
17:04:41,661 DEBUG LongType:133 - binding '3' to parameter: 2
17:04:41,661 DEBUG LongType:133 - binding '2' to parameter: 3
17:04:41,661 DEBUG AbstractCollectionPersister:1281 - done deleting collection rows: 1 deleted
17:04:41,661 DEBUG AbstractCollectionPersister:1313 - Inserting rows of collection: [jdpa.mlg.serverpool.domain.Application.resources#3]
17:04:41,661 DEBUG AbstractCollectionPersister:1390 - done inserting rows: 0 inserted
17:04:41,661 DEBUG AbstractCollectionPersister:1010 - Deleting collection: [jdpa.mlg.serverpool.domain.Application.clients#2]
17:04:41,661 DEBUG AbstractBatcher:44 - Executing batch size: 1
17:04:41,833 DEBUG NewPooledConnection:430 - com.mchange.v2.c3p0.impl.NewPooledConnection@107f672 handling a throwable.

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2009 12:32 pm 
Newbie

Joined: Thu Jan 15, 2009 7:27 pm
Posts: 4
Location: Boulder, CO
Hello, any suggestions here??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2009 1:59 pm 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
For some reason there seems to be a not null constraint on the field in the database
either try to set not-null="false" or remove the constraint manually
maybe this was the result of some of your earlier tries and you let hibernate generate the schema?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2009 4:28 pm 
Newbie

Joined: Thu Jan 15, 2009 7:27 pm
Posts: 4
Location: Boulder, CO
Yes, there is a not-null constraint. It's a many-to-many mapping table (two columns). It doesn't really make sense to have either of the columns nullable. Either one application is mapped to another application (through the two column resource), or its not.

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 4:56 am 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
Have you tried settings cascade-type to ALL?

Because you want to have the join-table-entry/ies deleted before deleting the main object


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 9:25 am 
Newbie

Joined: Sat Jan 17, 2009 5:13 am
Posts: 6
If there is not-null constraint in database, it should be in mappings too.
Adding it to mappings should solve your troubles.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

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.