views:

1549

answers:

3

i have problem i want to

select name_magazine from magazine

and i already import all library needed

and

Query q = EntityManger.createQuery ("SELECT name_magazine FROM Magazine");

List results = (List) q.getResultList ();

For(Sting s : result)

System.out.println(s);

but when i run this code it's error. can someone help me? Thx

this the error when i run the program

Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:859) at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:665) at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:357) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1220) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1261) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) at java.awt.Component.processMouseEvent(Component.java:6041) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5806) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4413) at java.awt.Container.dispatchEventImpl(Container.java:2116) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2440) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662) ... 29 more Caused by: java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:209) at tugas_rpl.Tugas_RPLView.Iseng(Tugas_RPLView.java:734) ... 34 more Caused by: Exception [TOPLINK-8034] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException Exception Description: Error compiling the query [Select m.Name from magazine m]. Unknown abstract schema type [magazine]. at oracle.toplink.essentials.exceptions.EJBQLException.unknownAbstractSchemaType(EJBQLException.java:494) at oracle.toplink.essentials.internal.parsing.ParseTreeContext.classForSchemaName(ParseTreeContext.java:163) at oracle.toplink.essentials.internal.parsing.VariableNode.resolveClass(VariableNode.java:280) at oracle.toplink.essentials.internal.parsing.DotNode.resolveMapping(DotNode.java:254) at oracle.toplink.essentials.internal.parsing.DotNode.endsWithDirectToField(DotNode.java:213) at oracle.toplink.essentials.internal.parsing.SelectNode.selectingDirectToField(SelectNode.java:440) at oracle.toplink.essentials.internal.parsing.SelectNode.hasOneToOneSelected(SelectNode.java:265) at oracle.toplink.essentials.internal.parsing.SelectNode.hasOneToOneSelected(SelectNode.java:222) at oracle.toplink.essentials.internal.parsing.SelectGenerationContext.computeUseParallelExpressions(SelectGenerationContext.java:105) at oracle.toplink.essentials.internal.parsing.SelectGenerationContext.(SelectGenerationContext.java:88) at oracle.toplink.essentials.internal.parsing.ParseTree.buildContextForReadQuery(ParseTree.java:382) at oracle.toplink.essentials.internal.parsing.ParseTree.buildContext(ParseTree.java:370) at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.buildContext(EJBQLParseTree.java:68) at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateQuery(EJBQLParseTree.java:107) at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:219) at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:189) at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:153) at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.(EJBQueryImpl.java:114) at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.(EJBQueryImpl.java:99) at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.(EJBQueryImpl.java:86) at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:204) ... 35 more

I already try Vincent Ramdhanie,Guðmundur Bjarni suggestion

Query q = entityManager.createQuery("Select m.name from magazine m");

List result = (List) q.getResultList();

For(Sting s : result)

System.out.print(s);

but still error

this what library & variable i use

private javax.persistence.EntityManager entityManager;

import org.jdesktop.application.Action;

import org.jdesktop.application.ResourceMap;

import org.jdesktop.application.SingleFrameApplication;

import org.jdesktop.application.FrameView;

import org.jdesktop.application.TaskMonitor;

import org.jdesktop.application.Task;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import java.util.List;

import javax.swing.Timer;

import javax.swing.Icon;

import javax.swing.JDialog;

import javax.swing.JFrame;

import javax.swing.event.ListSelectionEvent;

import javax.swing.event.ListSelectionListener;

import org.jdesktop.beansbinding.AbstractBindingListener;

import org.jdesktop.beansbinding.Binding;

import org.jdesktop.beansbinding.PropertyStateEvent;

import javax.persistence.*;

+1  A: 

You probably should say what the error is exactly.

However, assuming that you have an entity Magazine then the query should be:

 select m from Magazine m

If you want all magazines.

Vincent Ramdhanie
+1  A: 

For this to work, you need an entity defined as such:

@Entity
@Table(name = "magazines")
public class Magazine {
  /*
   * Some more attributes
   */

  @Column(name = "name_magazine")
  private String name;

  /*
   * Constructors, getters and setters
   */
}

Additionally you need a persistence.xml file pointing to your entity. If all of that is in place, this query should work and give you a list of all magazines.

from Magazine m

The query you specified is a projection of that, and with the entity I showed above it should be

select m.name from Magazine m

Hope this helps. :)

Guðmundur Bjarni
+2  A: 

The answer is right there in the call stack for your exception:

Error compiling the query [Select m.Jenis_Motor from motor m]. Unknown abstract schema type [motor].

It's not a problem with your magazine query, but another malformed query - probably a named query defined somewhere else.

Dan Vinton
Exactly right. +1
toolkit