# EclipseLink JPA - ManyToMany und Select Abfrage



## andyx1975 (22. Dez 2011)

Hallo,

ich habe gerade angefangen mich mit JPA auseinander zu setzen. Ich habe mir 2 Entity Klassen gebaut und diese über ManyToMany miteinander verbunden. Funktioniert auch soweit. 


*DEmail*

```
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.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
    @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;
    }

    public void addUpload( DUpload upload )
    {
        if ( !getUploads().contains( upload ) == false)
        {
            getUploads().add( upload );
        }
        if ( upload.getEmails().contains( this ) == false)
        {
            upload.getEmails().add( this );
        }
    }
    
    public void removeUpload( DUpload upload )
    {
        if ( getUploads().contains( upload ) == true)
        {
            getUploads().remove( upload );
        }
        if ( upload.getEmails().contains( this ) == true)
        {
            upload.getEmails().remove( this );
        }
    }

}
```


*DUploads*

```
package com.uds.webadmin.data;

import java.io.Serializable;
import java.lang.String;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

import static javax.persistence.TemporalType.TIMESTAMP;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 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" )
    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;
    }

    public List<DEmail> getEmails()
    {
        return emails;
    }

    public void setEmails( List<DEmail> emails )
    {
        this.emails = emails;
    }
    
}
```

Wenn ich jetzt aber den Select "SELECT e FROM DEmail e ORDER BY e.creation_date DESC" abfuere werden die zugewiesenen Uploads aus der "List<DUpload> uploads" nicht mit aufgeführt. Mein Ergbnis sieht wie folgt aus, also ohne die Uploads:

[XML]
<dEmails>
	<dEmail>
		<creation_date>2011-12-22T14:44:25.045+01:00</creation_date>
		<creator>Andy</creator>
		<email_id>151</email_id>
		<email_text>test test</email_text>
		<email_type>1</email_type>
		<headline>testAW</headline>
		<self_copy>false</self_copy>
		<to_recipients>test@web.de</to_recipients>
	</dEmail>
</dEmails>

[/XML]


ich möchte aber haben, dass die zugewiesenen Uploads auch aufgelistet werden. Sollte also wie folgt ausehen:

[XML]
<dEmails>
	<dEmail>
		<creation_date>2011-12-22T14:44:25.045+01:00</creation_date>
		<creator>Andy</creator>
		<email_id>151</email_id>
		<email_text>test test</email_text>
		<email_type>1</email_type>
		<headline>testAW</headline>
		<self_copy>false</self_copy>
		<to_recipients>test@web.de</to_recipients>
		<dUploads>
			<dUpload>
				<creation_date>2011-12-22T14:41:28.613+01:00</creation_date>
				<creator>Andy</creator>
				<edit_date>2011-12-22T14:41:28.613+01:00</edit_date>
				<editor>Andy</editor>
				<status>true</status>
				<upload_id>1</upload_id>
				<upload_link>2011_12_22_14_41_28_test.java</upload_link>
				<upload_name>test</upload_name>
				<upload_type>1</upload_type>
			</dUpload>
			<dUpload>
				<creation_date>2011-12-22T14:41:28.613+01:00</creation_date>
				<creator>Andy</creator>
				<edit_date>2011-12-22T14:41:28.613+01:00</edit_date>
				<editor>Andy</editor>
				<status>true</status>
				<upload_id>2</upload_id>
				<upload_link>2011_12_22_14_41_28_test2.java</upload_link>
				<upload_name>test2</upload_name>
				<upload_type>1</upload_type>
			</dUpload>
		</dUploads>
	</dEmail>
</dEmails>
[/XML]

Wie bekome ich das hin? Sorry ist vielleicht recht einfach zu lösen, bin aber recht neu in dem Thema JPA.

Danke
Andy


----------



## andyx1975 (23. Dez 2011)

Kann es sein, dass die List <DUpload> leer ist? Wenn ich im Debugger mir die Liste anschaue, bekomme ich anstatt den Inhalt, das folgende angezeigt???

{IndirectList: not instantiated}


----------



## andyx1975 (9. Jan 2012)

kann keiner weiter helfen? Danke!!!


----------



## Andreas (9. Jan 2012)

Die Liste wird erst instanziert, wenn du versuchst darauf zuzugreifen (wegen Lazy Loading), danach solltest du im Debugger etwas mehr sehen können. Oder stell mal 
	
	
	
	





```
fetch=FetchType.EAGER
```
 ein, dann wird die sofort geladen


----------



## andyx1975 (9. Jan 2012)

Hallo, danke für deine Antwort...ich habe das "fetch=FetchType.EAGER" integriert. Jetzt bekomme ich die folgende Fehlermeldung:


```
HTTP ERROR: 500
javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.uds.webadmin.data.DEmail@1799b90 -> com.uds.webadmin.data.DUpload@d43efc -> com.uds.webadmin.data.DEmail@1799b90]

RequestURI=/rest/emails/get/allEmails
Caused by:
javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.uds.webadmin.data.DEmail@1799b90 -> com.uds.webadmin.data.DUpload@d43efc -> com.uds.webadmin.data.DEmail@1799b90]
	at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:225)
	at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
	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.headerComplete(HttpConnection.java:829)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
	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: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.uds.webadmin.data.DEmail@1799b90 -> com.uds.webadmin.data.DUpload@d43efc -> com.uds.webadmin.data.DEmail@1799b90]
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:318)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
	at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.writeList(XMLListElementProvider.java:157)
	at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:223)
	... 25 more
Caused by: com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.uds.webadmin.data.DEmail@1799b90 -> com.uds.webadmin.data.DUpload@d43efc -> com.uds.webadmin.data.DEmail@1799b90
	at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:248)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.pushObject(XMLSerializer.java:537)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:631)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
	at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
	at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:324)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
	... 29 more
Caused by:
javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.uds.webadmin.data.DEmail@1799b90 -> com.uds.webadmin.data.DUpload@d43efc -> com.uds.webadmin.data.DEmail@1799b90]
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:318)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
	at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.writeList(XMLListElementProvider.java:157)
	at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:223)
	at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
	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.headerComplete(HttpConnection.java:829)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
	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: com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.uds.webadmin.data.DEmail@1799b90 -> com.uds.webadmin.data.DUpload@d43efc -> com.uds.webadmin.data.DEmail@1799b90
	at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:248)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.pushObject(XMLSerializer.java:537)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:631)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
	at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
	at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:324)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
	... 29 more
Caused by:
com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.uds.webadmin.data.DEmail@1799b90 -> com.uds.webadmin.data.DUpload@d43efc -> com.uds.webadmin.data.DEmail@1799b90
	at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:248)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.pushObject(XMLSerializer.java:537)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:631)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
	at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
	at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:324)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
	at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.writeList(XMLListElementProvider.java:157)
	at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:223)
	at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
	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.headerComplete(HttpConnection.java:829)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
	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)
```


Meine angepassten Klassen sehen jetzt wie folgt aus:

```
package com.uds.webadmin.data;

import java.io.Serializable;
import java.lang.String;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

import static javax.persistence.TemporalType.TIMESTAMP;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 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" )
    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;
    }

    public List<DEmail> getEmails()
    {
        return emails;
    }

    public void setEmails( List<DEmail> emails )
    {
        this.emails = emails;
    }
    
}
```


```
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;
    }

    public void addUpload( DUpload upload )
    {
        if ( !getUploads().contains( upload ) == false)
        {
            getUploads().add( upload );
        }
        if ( upload.getEmails().contains( this ) == false)
        {
            upload.getEmails().add( this );
        }
    }
    
    public void removeUpload( DUpload upload )
    {
        if ( getUploads().contains( upload ) == true)
        {
            getUploads().remove( upload );
        }
        if ( upload.getEmails().contains( this ) == true)
        {
            upload.getEmails().remove( this );
        }
    }

}
```


----------



## Andreas (9. Jan 2012)

Das ist jetzt ein JAXB Problem. Du kannst nicht deine Uploads in den Emails anzeigen UND die Emails in den Uploads. Markier am besten deine Email-Collection im Upload als 
	
	
	
	





```
@XmlTransient
```
. Das sollte klappen.


----------



## andyx1975 (9. Jan 2012)

also ich habe die Klasse wie folgt geändert, die Fehlermeldung bleibt aber bestehen:


```
@ManyToMany( mappedBy = "uploads" )
    @XmlTransient
    private List<DEmail> emails;
```


----------



## Andreas (9. Jan 2012)

Du musst die get-Methode annotieren. JAXB arbeitet per Default immer mit denen. Wenn die vorhanden sind und du die Felder annotierst gibt das mitunter lustige Faxen.


----------



## andyx1975 (9. Jan 2012)

Weltklasse...hat soweit funktioniert...vielen Dank für deine Hilfe!!!

Lösung:

```
@XmlTransient
    public List<DEmail> getEmails()
    {
        return emails;
    }
```


----------

