如何纠正使用netbean时出现的以下错误



我按照这个URL的教程;http://wiki.netbeans.org/DevelopJavaEE6App。

当我在以下行收到一些错误时,我卡住了;

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

如果你不介意的话,请看看我的代码并给我相应的建议。

谢谢亲切的问候

导入错误,如错误消息所示。

替换行

import javax.management.Query;

import javax.persistence.Query;

相关内容

  • 没有找到相关文章

最新更新