Hallo,
ich verwende EclipseLink / JPA für den Datenbank Zugriff und habe mir 2 Entity Klassen gebaut. Den Emails können Uploads zugewiesen werden. Hierzu gibt es die folgende Liste:
JPA legt zurzeit die Tabelle in PostgreSQL wie folgt an:
Mein Problem ist jetzt dass ich einen Upload nicht mehrmals der gleichen Email zuweisen kann. Hierbei bekomme ich eine Fehlermeldung. Kann ich das irgendwie abstellen?
Email Entity Klasse:
Upload Entity Klasse:
ich verwende EclipseLink / JPA für den Datenbank Zugriff und habe mir 2 Entity Klassen gebaut. Den Emails können Uploads zugewiesen werden. Hierzu gibt es die folgende Liste:
Java:
@ManyToMany ( fetch = FetchType.EAGER )
@JoinTable( name = "assignments_emails_uploads", joinColumns = @JoinColumn( name = "email_id", referencedColumnName = "email_id" ), inverseJoinColumns = @JoinColumn( name = "upload_id", referencedColumnName = "upload_id" ) )
private List<DUpload> uploads;
JPA legt zurzeit die Tabelle in PostgreSQL wie folgt an:
SQL:
CREATE TABLE assignments_emails_uploads
(
email_id serial NOT NULL,
upload_id serial NOT NULL,
CONSTRAINT assignments_emails_uploads_pkey PRIMARY KEY (email_id, upload_id),
CONSTRAINT fk_assignments_emails_uploads_email_id FOREIGN KEY (email_id)
REFERENCES email_sended (email_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_assignments_emails_uploads_upload_id FOREIGN KEY (upload_id)
REFERENCES email_uploads (upload_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (OIDS=TRUE);
ALTER TABLE assignments_emails_uploads OWNER TO postgres;
Mein Problem ist jetzt dass ich einen Upload nicht mehrmals der gleichen Email zuweisen kann. Hierbei bekomme ich eine Fehlermeldung. Kann ich das irgendwie abstellen?
Java:
[EL Warning]: 2012-01-12 13:28:41.059--UnitOfWork(2068447)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.BatchUpdateException: Batch-Eintrag 0 INSERT INTO assignments_emails_uploads (upload_id, email_id) VALUES ('801', '601') wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
Error Code: 0
Call: INSERT INTO assignments_emails_uploads (upload_id, email_id) VALUES (?, ?)
bind => [2 parameters bound]
javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.BatchUpdateException: Batch-Eintrag 0 INSERT INTO assignments_emails_uploads (upload_id, email_id) VALUES ('801', '601') wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
Error Code: 0
Call: INSERT INTO assignments_emails_uploads (upload_id, email_id) VALUES (?, ?)
bind => [2 parameters bound]
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
at com.uds.webadmin.server.CRestEmails.addAssignments(CRestEmails.java:178)
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 com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.BatchUpdateException: Batch-Eintrag 0 INSERT INTO assignments_emails_uploads (upload_id, email_id) VALUES ('801', '601') wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
Error Code: 0
Call: INSERT INTO assignments_emails_uploads (upload_id, email_id) VALUES (?, ?)
bind => [2 parameters bound]
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1494)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeJDK12BatchStatement(DatabaseAccessor.java:866)
at org.eclipse.persistence.internal.databaseaccess.ParameterizedSQLBatchWritingMechanism.executeBatchedStatements(ParameterizedSQLBatchWritingMechanism.java:144)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.writesCompleted(DatabaseAccessor.java:1707)
at org.eclipse.persistence.internal.sessions.AbstractSession.writesCompleted(AbstractSession.java:3821)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.writesCompleted(UnitOfWorkImpl.java:5509)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.acquireWriteLocks(UnitOfWorkImpl.java:1612)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitTransactionAfterWriteChanges(UnitOfWorkImpl.java:1580)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:273)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1135)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)
... 39 more
Caused by: java.sql.BatchUpdateException: Batch-Eintrag 0 INSERT INTO assignments_emails_uploads (upload_id, email_id) VALUES ('801', '601') wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2569)
at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:459)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1796)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2708)
at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.executeBatch(DatabasePlatform.java:2042)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeJDK12BatchStatement(DatabaseAccessor.java:860)
... 48 more
12.01.2012 13:28:41 com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SCHWERWIEGEND: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.UnsatisfiedLinkError: com.smartgwt.client.util.SC.say(Ljava/lang/String;)V
at com.smartgwt.client.util.SC.say(Native Method)
at com.uds.webadmin.server.CRestEmails.addAssignments(CRestEmails.java:186)
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 com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Email Entity Klasse:
Java:
package com.uds.webadmin.data;
import static javax.persistence.TemporalType.TIMESTAMP;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Entity implementation class for Entity: DEmail
*/
@Entity
@XmlRootElement
@Table( name = "email_sended" )
@NamedQuery( name = "findEmails", query = "SELECT e FROM DEmail e ORDER BY e.creation_date DESC" )
public class DEmail
implements Serializable
{
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
@SequenceGenerator( name = "email_sended_id_seq", sequenceName = "email_sended_id_seq", allocationSize = 1 )
@Column( columnDefinition = "SERIAL" )
private long email_id;
@Column( columnDefinition = "TEXT" )
private String to_recipients;
@Column( columnDefinition = "TEXT" )
private String cc_recipients;
@Column( columnDefinition = "TEXT" )
private String bcc_recipients;
@Column
private String headline;
@Column( columnDefinition = "TEXT" )
private String email_text;
@Column
private int email_type;
@Column
private Boolean self_copy;
@Column
private String creator;
@Column
@Temporal( TIMESTAMP )
private Date creation_date;
@ManyToMany ( fetch = FetchType.EAGER )
@JoinTable( name = "assignments_emails_uploads", joinColumns = @JoinColumn( name = "email_id", referencedColumnName = "email_id" ), inverseJoinColumns = @JoinColumn( name = "upload_id", referencedColumnName = "upload_id" ) )
private List<DUpload> uploads;
private static final long serialVersionUID = 1L;
public DEmail()
{
super();
}
public long getEmail_id()
{
return email_id;
}
public void setEmail_id( long email_id )
{
this.email_id = email_id;
}
public String getTo_recipients()
{
return to_recipients;
}
public void setTo_recipients( String to_recipients )
{
if ( to_recipients.trim().equals( "null" ) )
{
to_recipients = null;
}
this.to_recipients = to_recipients;
}
public String getCc_recipients()
{
return cc_recipients;
}
public void setCc_recipients( String cc_recipients )
{
if ( cc_recipients.trim().equals( "null" ) )
{
cc_recipients = null;
}
this.cc_recipients = cc_recipients;
}
public String getBcc_recipients()
{
return bcc_recipients;
}
public void setBcc_recipients( String bcc_recipients )
{
if ( bcc_recipients.trim().equals( "null" ) )
{
bcc_recipients = null;
}
this.bcc_recipients = bcc_recipients;
}
public String getHeadline()
{
return headline;
}
public void setHeadline( String headline )
{
if ( headline.trim().equals( "null" ) )
{
headline = null;
}
this.headline = headline;
}
public String getEmail_text()
{
return email_text;
}
public void setEmail_text( String email_text )
{
if ( email_text.trim().equals( "null" ) )
{
email_text = null;
}
this.email_text = email_text;
}
public int getEmail_type()
{
return email_type;
}
public void setEmail_type( int email_type )
{
this.email_type = email_type;
}
public Boolean getSelf_copy()
{
return self_copy;
}
public void setSelf_copy( Boolean self_copy )
{
this.self_copy = self_copy;
}
public String getCreator()
{
return creator;
}
public void setCreator( String creator )
{
this.creator = creator;
}
public Date getCreation_date()
{
return creation_date;
}
public void setCreation_date( Date creation_date )
{
this.creation_date = creation_date;
}
public List<DUpload> getUploads()
{
return uploads;
}
public void setUploads( List<DUpload> uploads )
{
this.uploads = uploads;
}
public static long getSerialversionuid()
{
return serialVersionUID;
}
}
Upload Entity Klasse:
Java:
package com.uds.webadmin.data;
import static javax.persistence.TemporalType.TIMESTAMP;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
* Entity implementation class for Entity: email_uploads
*/
@Entity
@Table( name = "email_uploads" )
@XmlRootElement
@NamedQuery( name = "findUploads", query = "SELECT e FROM DUpload e ORDER BY e.creation_date DESC" )
public class DUpload
implements Serializable
{
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
@SequenceGenerator( name = "email_uploads_id_seq", sequenceName = "email_uploads_id_seq", allocationSize = 1 )
@Column( columnDefinition = "SERIAL" )
private long upload_id;
@Column
private String upload_name;
@Column
private int upload_type;
@Column
private String creator;
@Column
private String upload_link;
@Column
private Boolean status;
@Column
@Temporal( TIMESTAMP )
private Date creation_date;
@Column
private String editor;
@Column
@Temporal( TIMESTAMP )
private Date edit_date;
@ManyToMany( mappedBy = "uploads", fetch = FetchType.EAGER )
private List<DEmail> emails;
private static final long serialVersionUID = 1L;
public DUpload()
{
}
public DUpload( long upload_id, String upload_name, int upload_type, String creator, String upload_link,
Boolean status, Date creation_date, String editor, Date edit_date )
{
this.upload_id = upload_id;
this.upload_name = upload_name;
this.upload_type = upload_type;
this.creator = creator;
this.upload_link = upload_link;
this.status = status;
this.creation_date = creation_date;
this.editor = editor;
this.edit_date = edit_date;
}
public long getUpload_id()
{
return upload_id;
}
public void setUpload_id( long upload_id )
{
this.upload_id = upload_id;
}
public String getUpload_name()
{
return upload_name;
}
public void setUpload_name( String upload_name )
{
this.upload_name = upload_name;
}
public int getUpload_type()
{
return upload_type;
}
public void setUpload_type( int upload_type )
{
this.upload_type = upload_type;
}
public String getCreator()
{
return creator;
}
public void setCreator( String creator )
{
this.creator = creator;
}
public String getUpload_link()
{
return upload_link;
}
public void setUpload_link( String upload_link )
{
this.upload_link = upload_link;
}
public Boolean getStatus()
{
return status;
}
public void setStatus( Boolean status )
{
this.status = status;
}
public Date getCreation_date()
{
return creation_date;
}
public void setCreation_date( Date creation_date )
{
this.creation_date = creation_date;
}
public String getEditor()
{
return editor;
}
public void setEditor( String editor )
{
this.editor = editor;
}
public Date getEdit_date()
{
return edit_date;
}
public void setEdit_date( Date edit_date )
{
this.edit_date = edit_date;
}
public static long getSerialversionuid()
{
return serialVersionUID;
}
@XmlTransient
public List<DEmail> getEmails()
{
return emails;
}
public void setEmails( List<DEmail> emails )
{
this.emails = emails;
}
}
Zuletzt bearbeitet: