2013-08-13 7 views
8

Utilizzo un server GlassFish 4.0 e classi basate su server JPA, che desidero recapitare tramite JAX-RS. Questo funziona fino ad ora per entità semplici. Tuttavia, se ho una relazione @OneToMany ad esempio E c'è un'entità collegata, il server restituisce un errore di 500 server interni. In tal caso, nulla viene registrato nel registro del server. Per trovare l'errore, ho creato una piccola pagina JSP personalizzata per ottenere maggiori informazioni su ciò che è successo. Il codice è proprio questo:GlassFish 4.0 w/Jersey restituisce errore interno del server 500 senza eccezioni

Status: <%= pageContext.getErrorData().getStatusCode() %> 
Throwable: <%= pageContext.getErrorData().getThrowable() %> 

Purtroppo, l'output è proprio "Stato: 500 Throwable: null"

My codice proprio server-sided sembra funzionare correttamente (ha fatto un po 'di output di debug), ma comunque , emerge un errore. In questo esempio, le classi utente ed emettere possono essere recuperati senza problemi a meno che non ci sia un'entità IssueComment collegato:

classe User:

package my.application.model; 

import static javax.persistence.FetchType.LAZY; 

import java.io.Serializable; 
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.OneToMany; 
import javax.persistence.Table; 
import javax.xml.bind.annotation.XmlRootElement; 

/** 
* The persistent class for the User database table. 
* 
*/ 
@XmlRootElement 
@Entity(name="User") 
@Table(name="User") 
public class User implements Serializable { 

    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name="id") 
    private int id; 

    @Column(name="failedLogin") 
    private short failedLogin; 

    @Column(name="firstname") 
    private String firstname; 

    @Column(name="lastname") 
    private String lastname; 

    @Column(name="middlename") 
    private String middlename; 

    @Column(name="password") 
    private String password; 

    @Column(name="username") 
    private String username; 

    //bi-directional many-to-one association to IssueComment 
    @OneToMany(mappedBy="user", fetch = LAZY) 
    private List<IssueComment> issueComments; 

    //bi-directional many-to-one association to SignalComment 
    @OneToMany(mappedBy="user", fetch = LAZY) 
    private List<SignalComment> signalComments; 

    //bi-directional many-to-one association to SignalMeasure 
    @OneToMany(mappedBy="user", fetch = LAZY) 
    private List<SignalMeasure> signalMeasures; 

    public User() { 
    } 

    public int getId() { 
     return this.id; 
    } 

     // more getters and setters auto-generated by Eclipse 
     } 

classe User:

package my.application.model; 

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.NamedQuery; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import javax.xml.bind.annotation.XmlRootElement; 

@NamedQuery(
    name = "getSingleIssue", 
    query = "SELECT i FROM Issue i WHERE i.id = :id" 
) 
/** 
* The persistent class for the Issue database table. 
* 
*/ 
@XmlRootElement 
@Entity(name="Issue") 
@Table(name="Issue") 
public class Issue implements Serializable { 

    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name="id") 
    private int id; 

    @Column(name="concernedModule") 
    private String concernedModule; 

    @Column(name="createdate") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date createdate; 

    @Column(name="duedate") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date duedate; 

    @Column(name="priority") 
    private int priority; 

    @Column(name="reminderdate") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date reminderdate; 

    @Column(name="responsibleUserId") 
    private int responsibleUserId; 

    @Column(name="sendingModule") 
    private String sendingModule; 

    @Column(name="severity") 
    private int severity; 

    @Column(name="status") 
    private int status; 

    @Column(name="title") 
    private String title; 

    // bidirectional many-to-one association to IssueComment 
    @OneToMany(mappedBy = "issue") 
    private List<IssueComment> issueComments; 

    public Issue() { 
    } 

    public int getId() { 
     return this.id; 
    } 

// more getters and setters.... 
} 

IssueComment:

package my.application.model; 

import java.io.Serializable; 

import javax.persistence.*; 

import java.util.Date; 


/** 
* The persistent class for the IssueComment database table. 
* 
*/ 
@Entity(name="IssueComment") 
@Table(name="IssueComment") 
public class IssueComment implements Serializable { 

    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue 
    @Column(name="id") 
    private int id; 

    @Lob 
    @Column(name="comment") 
    private String comment; 

    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name="time") 
    private Date time; 

    //bi-directional many-to-one association to Issue 
    @ManyToOne(fetch = FetchType.EAGER) 
    @JoinColumn(name="issueId") 
    private Issue issue; 

    //bi-directional many-to-one association to User 
    @ManyToOne(fetch = FetchType.EAGER) 
    @JoinColumn(name="userId") 
    private User user; 

    public IssueComment() { 
    } 

    public int getId() { 
     return this.id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

// getters/setters.... 
} 

Il servizio Web è il seguente:

Ho lasciato il codice sorgente del client poiché è lato server e può essere riprodotto con un normale browser, quindi nessuna necessità per il codice client qui IMHO.

+0

Sembra un'eccezione di puntatore nullo. Puoi eseguire il debug? –

+0

Hai attivato la modalità Sviluppo nel tuo web.xml? – unwichtich

+0

@Sotirios: Sfortunatamente no - quando provo ad impostare la registrazione su FINEST o ad avviare il server in modalità di debug, Eclipse riceve una eccezione TimeOutException quando tenta di avviare GlassFish. Proverò la modalità di sviluppo. Al momento non è attivo. – grobmotoriker

risposta

8

Assicurarsi di non avere riferimenti ciclici nel grafico (oggetti) che si sta tentando di eseguire il marshalling in XML. Per esempio, questo potrebbe causare un problema:

User -> IssueComment -> (the same) User 

o

User -> IssueComment -> Issue -> IssueComment -> (the same) User 

Tali strutture non possono essere dispiegate in XML.

Nota: Aggiungi @XmlRootElement annotazione IssueComment (penso che non è necessaria, ma è meglio averlo lì).

Nota: Siamo a conoscenza del problema di registrazione e verrà risolto come parte di JERSEY-2000.

+0

Ah, grazie! Lo controllerò domani! – grobmotoriker

+2

Ecco fatto! Grazie mille per le informazioni, anche per le informazioni sul problema di registrazione. Ho annotato gli attributi (per quell'esempio, l'attributo user e issue in IssueComment) con @XmlTransient in modo che non vengano presi in considerazione durante il marshalling dell'oggetto. – grobmotoriker

+3

Ulteriori informazioni: se si verifica questo problema - non gli attributi, ma i metodi getter devono essere annotati con @XmlTransient – grobmotoriker

Problemi correlati