# QuerySyntaxException is not mapped (RCP)



## algebraiker (21. Okt 2011)

Hi,

mal wieder ein solches Problem und ich weiß nicht, warum es nicht funktioniert. 

Ich habe eine Klasse ArticleEditor geschrieben, die von EditorPart erbt. Der Editor öffnet sich auch neben der View. Die View stellt die Datensätze, die aus meiner Datenbank mittels Hibernate geholt werden, dar. (Das passiert in einer Klasse ModelProvider). Soweit so gut. 

Bei einem Doppelklick in eine Zeile in der View, öffnet sich der Editor, mit dem ich den bestehenden Datensatz in der Tabelle updaten möchte.







Dazu habe ich in der Klasse ArticleEditor folgendes gemacht:


```
@Override
	public void createPartControl(Composite parent) {
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		parent.setLayout(layout);
		Label label1 = new Label(parent, SWT.NONE);
		label1.setText("Artikelname");
		text = new Text(parent, SWT.BORDER);
		text.setText(article.getName());
		text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
		new Label(parent, SWT.NONE).setText("Artikelpreis");
		lprice = new Text(parent, SWT.BORDER);
		lprice.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
		lprice.setText("" + article.getPrice());
		Button button = new Button(parent, SWT.PUSH);
		button.setText("Update Artikel");
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				
				EntityManagerFactory emf = Persistence
						.createEntityManagerFactory("adp");

				EntityManager em = emf.createEntityManager();
				EntityTransaction tx = em.getTransaction();

				tx.begin();
				Query q = em.createQuery("update article a "
						+ "SET a.name=:name, a.price=:price "
						+ "WHERE a.number = :number");
				
				q.setParameter("name", text.getText());
				q.setParameter("price",Float.parseFloat(lprice.getText()));
				q.setParameter("number", article.getNumber());
				q.executeUpdate();
				tx.commit();
			}
		});
	}
```

Debugging hat ergeben, dass diese Parameter korrekt geholt werden:


```
q.setParameter("name", text.getText());
				q.setParameter("price",Float.parseFloat(lprice.getText()));
				q.setParameter("number", article.getNumber());
```

Nun bekomme ich folgende Exception:


```
!ENTRY org.eclipse.ui 4 0 2011-10-21 13:14:34.413
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: article is not mapped [update article a SET a.name=:name, a.price=:price WHERE a.number = :number]
	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1334)
	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1280)
	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:283)
	at toolgui.ArticleEditor$1.widgetSelected(ArticleEditor.java:87)
	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:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at toolgui.Application.start(Application.java:20)
	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)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: article is not mapped [update article a SET a.name=:name, a.price=:price WHERE a.number = :number]
	at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:178)
	at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
	at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:92)
	at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:324)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3252)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3141)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:694)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:351)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:243)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:120)
	at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214)
	at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:192)
	at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1538)
	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:280)
	... 27 more
```

Die Klasse Article sieht so aus:



```
package model;

import java.beans.PropertyChangeSupport;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Article extends BaseEntity {

	

	public Article() {
		
	}

	// Die eindeutige Artikelnummer des Artikels (String, weil manche Systeme
	// auch Buchstaben in Artikelnummern haben)
	@Column(nullable = false, unique = true)
	private String number;

	// Die Bezeichnung des Artikels
	@Column(nullable = false)
	private String name;

	// Der Preis des Artikels (optional), sofern eine Bewertung vorgenommen
	// werden soll
	private float price;

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		String old = this.name;
		this.name = name;
		PropertyChangeSupport propertyChangeSupport;
		propertyChangeSupport = new PropertyChangeSupport(this);
		propertyChangeSupport.firePropertyChange("name", old, name);
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		// this.price = price;
		float old = this.price;
		PropertyChangeSupport propertyChangeSupport;
		propertyChangeSupport = new PropertyChangeSupport(this);
		propertyChangeSupport.firePropertyChange("price", old, price);
	}
}
```

[XML]<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd"
	version="1.0">

	<!-- JPA test "unit" -->
	<persistence-unit name="adp" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<class>model.Article</class>
		<class>model.ModelProvider</class>
		<class>toolgui.ArticleEditor</class>
		<properties>
			<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
			<property name="hibernate.connection.url" value="jdbcostgresql://localhost:5432/prog" />
			<property name="hibernate.connection.username" value="postgres" />
			<property name="hibernate.connection.password" value="database" />
			<property name="hibernate.connection.pool_size" value="5" />
			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
			<property name="hibernate.hbm2ddl.auto" value="update" />
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
		</properties>
	</persistence-unit>

</persistence>[/XML]

Was tun?


----------



## maki (21. Okt 2011)

[c]Article[/c] anstatt [c]article[/c]?


----------



## algebraiker (21. Okt 2011)

Mann, was war ich blind. DANKE!


----------

