0

我和我的团队目前正在使用 Hibernate-Validation 和 JPA 进行项目。

问题:我们决定在开发阶段使用“drop-and-create-table”。一切正常,随着一切的实施​​,我们将生成模式更改为“无”(运行稳定的数据库)。

它之前在做什么:我们删除表,从具有特定属性的实体创建表,并用一些数据集填充表。

它现在在做什么:我们处理现有的、以前工作的表(已经填充了一些数据);但现在似乎缺少一些关系。

现在我们在运行时遇到了一些异常,我们找不到它们。似乎,一些属性关系被删除了,因为之前没有抛出异常(例如 NullPointerExceptions)。

除了生成模式,我们还需要在persistence.xml 中更改什么吗?

这是persistance.xml的代码:

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="ticketline" transaction-type="RESOURCE_LOCAL">

        <class>at.ticketline.entity.Veranstaltung</class>
        <class>at.ticketline.entity.Saal</class>
        <class>at.ticketline.entity.Reihe</class>
        <class>at.ticketline.entity.Platz</class>
        <class>at.ticketline.entity.Person</class>
        <class>at.ticketline.entity.Ort</class>
        <class>at.ticketline.entity.News</class>
        <class>at.ticketline.entity.Kunde</class>
        <class>at.ticketline.entity.Kuenstler</class>
        <class>at.ticketline.entity.Kategorie</class>
        <class>at.ticketline.entity.Bestellung</class>
        <class>at.ticketline.entity.BestellPosition</class>
        <class>at.ticketline.entity.BaseEntity</class>
        <class>at.ticketline.entity.Auffuehrung</class>
        <class>at.ticketline.entity.Artikel</class>
        <class>at.ticketline.entity.Adresse</class>
        <class>at.ticketline.entity.Benutzer</class>
        <class>at.ticketline.entity.Ticket</class>
        <class>at.ticketline.entity.compositekeys.PlatzPK</class>
        <class>at.ticketline.entity.compositekeys.ReihePK</class>
        <class>at.ticketline.entity.compositekeys.SaalPK</class>
        <class>at.ticketline.entity.compositekeys.AuffuehrungPK</class>

        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost/ticketline" />
            <property name="javax.persistence.jdbc.user" value="sa" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="eclipselink.ddl-generation" value="none" />              
        </properties>
    </persistence-unit>
</persistence>

堆栈跟踪:

!STACK 0
java.lang.NullPointerException
    at at.ticketline.kassa.ui.editor.TicketSuchergebnisEditor$11.getText(TicketSuchergebnisEditor.java:253)
    at org.eclipse.jface.viewers.ColumnLabelProvider.update(ColumnLabelProvider.java:36)
    at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:152)
    at org.eclipse.jface.viewers.AbstractTableViewer.doUpdateItem(AbstractTableViewer.java:399)
    at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:485)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2167)
    at org.eclipse.jface.viewers.AbstractTableViewer.createItem(AbstractTableViewer.java:277)
    at org.eclipse.jface.viewers.AbstractTableViewer.internalRefreshAll(AbstractTableViewer.java:757)
    at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:649)
    at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:636)
    at org.eclipse.jface.viewers.AbstractTableViewer$2.run(AbstractTableViewer.java:592)
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1443)
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1404)
    at org.eclipse.jface.viewers.AbstractTableViewer.inputChanged(AbstractTableViewer.java:590)
    at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:280)
    at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1690)
    at at.ticketline.kassa.ui.editor.TicketSuchergebnisEditor.createPartControl(TicketSuchergebnisEditor.java:67)
    at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:670)
    at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
    at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
    at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
    at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
    at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
    at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
    at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
    at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
    at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
    at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
    at org.eclipse.ui.internal.PartStack.add(PartStack.java:493)
    at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103)
    at org.eclipse.ui.internal.PartStack.add(PartStack.java:479)
    at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112)
    at org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.java:63)
    at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:225)
    at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:213)
    at org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:808)
    at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager.java:707)
    at org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:666)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2942)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2850)
    at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2842)
    at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2793)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2789)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2773)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2756)
    at at.ticketline.kassa.ui.command.TicketSucheResultsCommandHandler.execute(TicketSucheResultsCommandHandler.java:28)
    at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
    at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
    at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:178)
    at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
    at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
    at at.ticketline.kassa.ui.view.TicketSucheView.openEditor(TicketSucheView.java:246)
    at at.ticketline.kassa.ui.view.TicketSucheView$1.widgetSelected(TicketSucheView.java:194)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at at.ticketline.kassa.TicketlineApplication.start(TicketlineApplication.java:21)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
4

1 回答 1

0

我的猜测是您的数据库缺少一些数据。

当您在内存中运行填充时,您正在填充共享缓存和数据库。但是,您很可能无法正确构建对象。

也许您在内存中设置了瞬态字段,但是当您从数据库中读取时,这些瞬态字段为空。

也许您有双向关系并且没有设置关系的双方,因此没有正确填充数据库。

也许你没有正确映射一些属性,所以数据库中的数据不正确。

我的猜测是,如果你禁用了共享缓存,你也会遇到同样的错误。

于 2012-06-20T12:52:04.683 回答