Duvida com update[Resolvido]

5 respostas
G

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();
			}
	}

5 Respostas

nel

Poste seu DAO com o método do update. Mas como o erro mesmo aponta:

ORA-01400: cannot insert NULL into ("GI"."SYSTEM_APPLICATION"."CODE_APPLICATION")

Provavél que esteja inserindo um null em alguma coluna. Faça um debug do seu código e verifique esta linha.
Abraços

G

nel:
Poste seu DAO com o método do update. Mas como o erro mesmo aponta:

ORA-01400: cannot insert NULL into ("GI"."SYSTEM_APPLICATION"."CODE_APPLICATION")

Provavél que esteja inserindo um null em alguma coluna. Faça um debug do seu código e verifique esta linha.
Abraços

entao, engraçado mas eu to pegando essas informaçoes de uma tabela, e ela esta preenchida tanto que no insert funciona normalmente =x, mas realmente ta vindo null se caso uma aplicaçao esteja associado a um sistema ele nao reconhece e joga ele como null…

eu preencho a table dessa forma.

private void fillTableSa() { Collection<Application> itemsApplication = s.getApplications(); for (Application a : itemsApplication) { itemSA = new TableItem(tableSA, SWT.NONE); itemSA.setText(new String[] { a.getName(), a.getDescription() }); itemSA.setData(a.getName(), a.getCode()); } }

nel

Veja bem, quando você está inserindo seu(s) objeto(s) podem estar populados, ou seja, com valores atribuidos. Entretanto, quando está tentando efetuar o update, um ou mais campos podem estar nulos, o que gera uma excessão.

G

cara funcionou muitop obrigado
é pq eu nao sei mas tava setando quando preenchia a tabela as datas name e code

public void fillTableSa() { Collection<Application> itemsApplication = s.getApplications(); for (Application a : itemsApplication) { itemSA = new TableItem(tableSA, SWT.NONE); itemSA.setText(new String[] { a.getName(), a.getDescription() }); itemSA.setData(a); } }

dai setei aplication toda e deu certo =)

nel

É isso ai! :slight_smile:
Então, poste [Resolvido] ao lado do seu tópico agora ok?

E boa programação! Abraços! :slight_smile:

Criado 4 de novembro de 2009
Ultima resposta 4 de nov. de 2009
Respostas 5
Participantes 2