开发者

how to rectify the following error while using netbean?

I am following the tutorial according to this URL; http://wiki.netbeans.org/DevelopJavaEE6App .

I get stuck when I receive some errors at the following lines;

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

The errors read as follow;

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

AND SECONDLY

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

I do not understand these errors, as I do have the following imported.

javax.management.Query;

Here is my full code for my file - 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.e开发者_运维知识库jb.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();
}
}
}
}

Please have a look at my code and advice me accordingly, if you do not mind.

Thank you Kind regards


You have a wrong import as the error message states.

Replace the line

import javax.management.Query;

with

import javax.persistence.Query;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜