Boa tarde, tenho a seguinte situação, tenho uma classe chamada system e ela tem relacionamento de n para n com uma classe application logo cria-se uma classe associativa, e nessa classe system tenho uma coleçao de application e eu consigo inserir a coleçao normalmente porem quando vou atualizar da um erro e nao aceita atualizar essa coleçao
22532 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at br.com.md2net.gi.dao.SystemDAO.update(SystemDAO.java:91)
at br.com.md2net.gi.dialogs.SystemDialog.update(SystemDialog.java:336)
at br.com.md2net.gi.dialogs.SystemDialog.okPressed(SystemDialog.java:269)
at org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:472)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at br.com.md2net.gi.view.TableSystemView$3.mouseDoubleClick(TableSystemView.java:85)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:183)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at br.com.md2net.gi.application.Application.start(Application.java:23)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
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:386)
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:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("GI"."SYSTEM_APPLICATION"."CODE_APPLICATION")
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8739)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 46 more
a classe que faz o update é aseguinte
public void update() {
System system = new System();
SystemDAO systemDao = new SystemDAO();
String sys = TableSystemView.table.getItem(TableSystemView.table.getSelectionIndex()).getText(0);
system = systemDao.getSystem(Integer.parseInt(TableSystemView.table.getItem(TableSystemView.table.getSelectionIndex()).getData(sys).toString()));
system.setDescription(descriptionSystem.getText());
system.setName(nameSystem.getText());
int c = masterSystem.getSelectionIndex();
Employee emp = empDao.getEmployee(Integer.parseInt(masterSystem
.getData(masterSystem.getItem(c)).toString()));
system.setEmployee(emp);
Collection<Application> listApp = new HashSet<Application>();
for (TableItem t : tableSA.getItems()) {
listApp.add((Application) t.getData());
}
system.setApplications(listApp);
systemDao.update(system);
TableSystemView.table.remove(TableSystemView.table.getSelectionIndex());
TableItem item = new TableItem(TableSystemView.table, SWT.NONE);
item.setText(new String[] { nameSystem.getText(),
masterSystem.getText().toString(),
descriptionSystem.getText() });
item.setData(system);
TableSystemView.table.update();
}
e consigo inserir normalmente portanto vou colocar aqui a classe de insert para voces poderem ver
public void insert() {
System system = new System();
system.setDescription(descriptionSystem.getText());
system.setName(nameSystem.getText());
int c = masterSystem.getSelectionIndex();
Employee emp = empDao.getEmployee(Integer.parseInt(masterSystem
.getData(masterSystem.getItem(c)).toString()));
system.setEmployee(emp);
Collection<Application> listApp = new HashSet<Application>();
for (TableItem t : tableSA.getItems()) {
listApp.add((Application) t.getData());
}
system.setApplications(listApp);
SystemDAO systemDao = new SystemDAO();
systemDao.insert(system);
if (TableSystemView.table != null)
if (!TableSystemView.table.isDisposed()) {
TableItem item = new TableItem(TableSystemView.table, SWT.NONE);
item.setText(new String[] { nameSystem.getText(),
masterSystem.getText().toString(),
descriptionSystem.getText() });
item.setData(system);
TableSystemView.table.update();
}
}
