Michael K. Michael K. - 1 month ago 18
Java Question

JPA Entity Parse Error

Ever since converting my JavaFX project into a Maven project, I can't access the Entity

BenutzerKonversation
anymore. I also got the error message that the annotation
@IdClass
is needed when having 2 or more primary keys. After adding that annotation and creating the required class
BenutzerKonversationId
, I got a
ParseError
.

After a few tests I can definitely say that it has something to do with the entity
BenutzerKonversation
. My Entities are part of a WebService (JAX-WS). When returning the Entity, a
ParseError
occurs. The entities' outputs before returning are correct and contain the expected values.

When starting the WebService, I also noticed the following SQL warning message:

SQL-Warning:

Internal Exception:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:Table 'benutzer' already exists
Error Code: 1050
Call: CREATE TABLE BENUTZER (id INTEGER NOT NULL, nachname VARCHAR(255), prueferNr INTEGER, status INTEGER, vorname VARCHAR(255), PRIMARY KEY (id))
Query: DataModifyQuery(sql="CREATE TABLE BENUTZER (id INTEGER NOT NULL, nachname VARCHAR(255), prueferNr INTEGER, status INTEGER, vorname VARCHAR(255), PRIMARY KEY (id))")


Persistence.xml:

<class>entity.Benutzer</class>
<class>entity.Konversation</class>
<class>entity.BenutzerKonversation</class>

<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/projekt8592Db"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
</properties>




When querying the Entity
Benutzer
from the Webservice (using a static
BenutzerService.findById(1)
for testing purposes) and there are
BenutzerKonversation
s in the database, I get the following parse error:

Exception:

javafx.fxml.LoadException:/...Path...View.fxml:13
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:14)
at

com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.xml.internal.ws.encoding.soap.DeserializationException: [failed to localize] Die Antwort konnte nicht deserialisiert werden.(javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,192]
Message: XML-Dokumentstrukturen müssen innerhalb derselben Entität beginnen und enden.])
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
at com.sun.proxy.$Proxy38.getUserById(Unknown Source)
at launch.CClient.<init>(CClient.java:28)
at application.Controller.<init>(Controller.java:62)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 17 more
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,192]
Message: XML-Dokumentstrukturen müssen innerhalb derselben Entität beginnen und enden.]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:470)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:402)
at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:109)
at com.sun.xml.internal.bind.api.Bridge.unmarshal(Bridge.java:222)
at com.sun.xml.internal.ws.db.glassfish.BridgeWrapper.unmarshal(BridgeWrapper.java:257)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:635)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:243)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:104)
... 34 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,192]
Message: XML-Dokumentstrukturen müssen innerhalb derselben Entität beginnen und enden.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596)
at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:81)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:181)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:400)
... 42 more


BenutzerKonversation (Many-To-Many Entity):

@Entity
@Table(name="benutzer_konversation")
@IdClass(BenutzerKonversationId.class)
@NamedQueries({
@NamedQuery(
name="BenutzerKonversation.findAll",
query="SELECT bk FROM BenutzerKonversation bk"
)
})

public class BenutzerKonversation {

@Id
private int benutzer_id;

@Id
private int konversation_id;

@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "benutzer_id",nullable=false, updatable = false, insertable = false)
private Benutzer benutzer;

@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "konversation_id",nullable=false, updatable = false, insertable = false)
private Konversation konversation;

@Column(name="status",nullable=false,updatable=true,insertable=true)
private int status;
}


Benutzer (Entity)

@OneToMany(mappedBy="benutzer",cascade=CascadeType.PERSIST)
private List<BenutzerKonversation> konversationen = new ArrayList<>();


Konversation (Entity)

@OneToMany(mappedBy="konversation",cascade=CascadeType.PERSIST)
private List<BenutzerKonversation> benutzer;


SOAP UI Response:

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:getUserByIdResponse xmlns:ns2="http://webservice/">
<return><konversationen><benutzer


I got this Response from SOAP UI, after querying
BenutzerService.findById(1)
.

Answer

The Problem was, that my DTO (Data Transfer Object) wasn't complete. I realized, that I set an Empty List of "BenutzerKonversation" and try to return it incomplete to the Client, that's why the Problem occurs.