2011-10-13 27 views
0

我正在按照這個URL跟隨教程; http://wiki.netbeans.org/DevelopJavaEE6App如何在使用netbean時糾正以下錯誤?

我在下面幾行收到錯誤時卡住了;

Query query = em.createNamedQuery("Customer.findAll"); 
return query.getResultList(); 

錯誤如下:

" incompatible types 
required: javax.management.Query 
found: javax. persistence.Query" 

其次

" cannot find symbol 
symbol: method getResultList() 
location: class javax.management.Query" 

我不明白這些錯誤,我有以下進口。

javax.management.Query;

這是我爲我的文件全碼 - CustomerSession.java

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package com.customerapp.ejb; 

import com.customerapp.entity.Customer; 
import java.io.Serializable; 
import java.util.List; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.annotation.Resource; 
import javax.ejb.Stateless; 
import javax.ejb.LocalBean; 
import javax.jms.Connection; 
import javax.jms.ConnectionFactory; 
import javax.jms.JMSException; 
import javax.jms.Message; 
import javax.jms.MessageProducer; 
import javax.jms.ObjectMessage; 
import javax.jms.Queue; 
import javax.jms.Session; 
import javax.management.Query; 
import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 

// Add business logic below. (Right-click in editor and choose 
// "Insert Code > Add Business Method") 
/** 
* 
* @author Padjester 
*/ 
@Stateless 
@LocalBean 
public class CustomerSession { 

@PersistenceContext 
private EntityManager em; 

/** 
* Returns a list of customer objects in the database * 
* @return List<Customer> 
*/ 
public List<Customer> retrieve() { 
Query query = em.createNamedQuery("Customer.findAll"); 
return query.getResultList(); 
} 
/** 
*Update the customer record 
* @param customer object to be updated 
* @return Customer 
*/ 
@Resource(name = "jms/NotificationQueue") 
private Queue notificationQueue; 
@Resource(name = "jms/NotificationQueueFactory") 
private ConnectionFactory notificationQueueFactory; 

public Customer update(Customer customer) { 
Customer updated = em.merge(customer); 
try { 
sendJMSMessageToNotificationQueue(updated); 
} catch (JMSException ex) { 
Logger.getLogger(CustomerSession.class.getName()).log(Level.SEVERE, null, ex); 
} 
System.out.println("Customer updated in CustomerSession!"); 
return updated; 
} 

private Message createJMSMessageForjmsNotificationQueue(Session session, Object messageData) throws JMSException { 
//Modified to use ObjectMessage instead 
ObjectMessage tm = session.createObjectMessage(); 
tm.setObject((Serializable) messageData); 
return tm; 
} 

private void sendJMSMessageToNotificationQueue(Object messageData) throws JMSException { 
Connection connection = null; 
Session session = null; 
try { 
connection = notificationQueueFactory.createConnection(); 
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
MessageProducer messageProducer = session.createProducer(notificationQueue); 
messageProducer.send(createJMSMessageForjmsNotificationQueue(session, messageData)); 
} finally { 
if (session != null) { 
try { 
session.close(); 
} catch (JMSException e) { 
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close session", e); 
} 
} 
if (connection != null) { 
connection.close(); 
} 
} 
} 
} 

請看看我的代碼,並建議我因此,如果你不介意。

謝謝 親切的問候

回答

2

你有一個錯誤的進口作爲錯誤信息的狀態。

替換行

import javax.management.Query; 

import javax.persistence.Query; 
+0

我這個import語句編輯,但其仍顯示相同類型的錯誤。 –

+0

也許你必須清理和構建才能使錯誤消失。 –