users@glassfish.java.net

Re: Please Help !! Error connecting glassfish to MS SQL server at run time

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Tue, 27 May 2008 12:08:59 -0700

The stack trace you have included below is because of a typo in one of
your ejbqls. Grep for query "select c from country c" in your code (Note
small c in country)

<snip>
Caused by: Exception [TOPLINK-8034] (Oracle TopLink Essentials - 2.0
(Build b58g-fcs (09/07/2007))):
oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Error compiling the query [select c from country
c]. Unknown abstract schema type [country].
  at
oracle.toplink.essentials.exceptions.EJBQLException.unknownAbstractSchemaType(EJBQLException.java:494)
<snip>

glassfish_at_javadesktop.org wrote:
> Hi all ,
> I am trying to connect to Microsoft SQL server from gassfish using the jtds driver ,the "microsoft_jtds_datasource.xml" in is the "C:\Program Files\glassfish-v2\domains\domain1\lib\ext" directory
> [CODE]
> <resources>
> <jdbc-connection-pool
> name="microsoft_jtds_pool"
> datasource-classname="net.sourceforge.jtds.jdbcx.JtdsDataSource"
> res-type="javax.sql.DataSource">
> <property name="user" value="devuser"/>
> <property name="password" value="devapp"/>
> <property name="serverName" value="db-developer"/>
> <property name="portNumber" value="1433"/>
> <property name="databaseName" value="qualcheck"/>
> </jdbc-connection-pool>
>
> <jdbc-resource
> enabled="true"
> jndi-name="jdbc/microsoft_jtds_resource"
> object-type="user"
> pool-name="microsoft_jtds_pool"/>
> </resources>
>
> [/CODE]
>
>
> my persistance.xml is
> [CODE]
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.0" 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">
> <persistence-unit name="JV-ejbPU" transaction-type="JTA">
> <jta-data-source>jdbc/microsoft_jtds_resource</jta-data-source>
> <properties/>
> </persistence-unit>
> </persistence>
>
> [/CODE]
>
> I created the entity class from the database using the netbeans IDE
>
> [CODE]
> /*
> * To change this template, choose Tools | Templates
> * and open the template in the editor.
> */
>
> package jv.ejb;
>
> import java.io.Serializable;
> import java.util.Collection;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.NamedQueries;
> import javax.persistence.NamedQuery;
> import javax.persistence.OneToMany;
> import javax.persistence.Table;
>
> /**
> *
> * @author BomanbehramM
> */
> @Entity
> @Table(name = "country")
> @NamedQueries({_at_NamedQuery(name = "Country.findByCountryCode", query = "SELECT c FROM Country c WHERE c.countryCode = :countryCode"), @NamedQuery(name = "Country.findByCountryName", query = "SELECT c FROM Country c WHERE c.countryName = :countryName")})
> public class Country implements Serializable {
> private static final long serialVersionUID = 1L;
> @Id
> @Column(name = "country_code", nullable = false)
> private String countryCode;
> @Column(name = "country_name", nullable = false)
> private String countryName;
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "countryCode")
> private Collection<State> stateCollection;
>
> public Country() {
> }
>
> public Country(String countryCode) {
> this.countryCode = countryCode;
> }
>
> public Country(String countryCode, String countryName) {
> this.countryCode = countryCode;
> this.countryName = countryName;
> }
>
> public String getCountryCode() {
> return countryCode;
> }
>
> public void setCountryCode(String countryCode) {
> this.countryCode = countryCode;
> }
>
> public String getCountryName() {
> return countryName;
> }
>
> public void setCountryName(String countryName) {
> this.countryName = countryName;
> }
>
> public Collection<State> getStateCollection() {
> return stateCollection;
> }
>
> public void setStateCollection(Collection<State> stateCollection) {
> this.stateCollection = stateCollection;
> }
>
> @Override
> public int hashCode() {
> int hash = 0;
> hash += (countryCode != null ? countryCode.hashCode() : 0);
> return hash;
> }
>
> @Override
> public boolean equals(Object object) {
> // TODO: Warning - this method won't work in the case the id fields are not set
> if (!(object instanceof Country)) {
> return false;
> }
> Country other = (Country) object;
> if ((this.countryCode == null && other.countryCode != null) || (this.countryCode != null && !this.countryCode.equals(other.countryCode))) {
> return false;
> }
> return true;
> }
>
> @Override
> public String toString() {
> return "jv.ejb.Country[countryCode=" + countryCode + "]";
> }
>
> }
>
> [/CODE]
> I call this class from my session bean
>
> [CODE]
> /*
> * To change this template, choose Tools | Templates
> * and open the template in the editor.
> */
>
> package jv.ejb;
>
> import java.util.List;
> import javax.ejb.EJBContext;
> import javax.ejb.Stateless;
> import javax.persistence.EntityManager;
> import javax.persistence.PersistenceContext;
> import javax.persistence.Query;
>
> /**
> *
> * @author BomanbehramM
> */
> @Stateless
> public class CountrySessionBean implements CountrySessionLocal {
> @PersistenceContext
> private EntityManager em;
>
>
> public String getStaticStringEjbData() {
> String s = new String("This is some static data from the EJB stateless Session +"+ EJBContext.class );
> return s;
> }
>
> public List getAllCountries() {
>
> Query q = em.createQuery("select c from country c");
> return q.getResultList();
> }
>
> public void persist(Object object) {
> em.persist(object);
> }
>
>
> }
> [/CODE]
> which is in turn called from m servlet
> [CODE]
> /*
> * To change this template, choose Tools | Templates
> * and open the template in the editor.
> */
>
> package jv.web;
>
> import java.io.*;
> import java.net.*;
>
> import java.util.Iterator;
> import java.util.List;
> import javax.ejb.EJB;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import jv.ejb.Country;
> import jv.ejb.CountrySessionLocal;
>
> /**
> *
> * @author BomanbehramM
> */
> public class jvServlet extends HttpServlet {
> @EJB
> private CountrySessionLocal countrySessionBean;
>
> /**
> * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
> * @param request servlet request
> * @param response servlet response
> */
> protected void processRequest(HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException {
> response.setContentType("text/html;charset=UTF-8");
> PrintWriter out = response.getWriter();
> try {
> // TODO output your page here
> out.println("<html>");
> out.println("<head>");
> out.println("<title>Servlet jvServlet</title>");
> out.println("</head>");
> out.println("<body>");
> out.println("<h1>Servlet jvServlet at " + request.getContextPath () + "</h1>");
> out.println(countrySessionBean.getStaticStringEjbData());
> List countryList = countrySessionBean.getAllCountries();
> for (Iterator i = countryList.iterator();i.hasNext(); ){
> Country c = (Country)i.next();
> out.println(c.getCountryCode());
> out.println("ggdgdfgd");
> out.println( c.getCountryName());
> }
> out.println("</body>");
> out.println("</html>");
>
> }catch (Exception ex){
> out.println (ex.getMessage());
> }
> finally {
> out.close();
> }
> }
>
> // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
> /**
> * Handles the HTTP <code>GET</code> method.
> * @param request servlet request
> * @param response servlet response
> */
> protected void doGet(HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException {
> processRequest(request, response);
> }
>
> /**
> * Handles the HTTP <code>POST</code> method.
> * @param request servlet request
> * @param response servlet response
> */
> protected void doPost(HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException {
> processRequest(request, response);
> }
>
> /**
> * Returns a short description of the servlet.
> */
> public String getServletInfo() {
> return "Short description";
> }
> // </editor-fold>
> }
>
> [/CODE]
> but when I try to run this application I get the following eror could someone pls tel me why and how to sort this out ?
>
>
> [QUOTE]
> Application server startup complete.
> CORE5022: All ejb(s) of [JV] were unloaded successfully!
> deployed with moduleid = JV
> naming.bind
> LDR5010: All ejb(s) of [JV] loaded successfully!
> TopLink, version: Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))
> Server: unknown
> file:/C:/Documents%20and%20Settings/BomanbehramM/My%20Documents/NetBeansProjects/JV/dist/gfdeploy/JV-ejb_jar/-JV-ejbPU login successful
> EJB5018: An exception was thrown during an ejb invocation on [CountrySessionBean]
> javax.ejb.EJBException
> at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3869)
> at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3769)
> at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3571)
> at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1354)
> at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
> at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:205)
> at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
> at $Proxy57.getAllCountries(Unknown Source)
> at jv.web.jvServlet.processRequest(jvServlet.java:45)
> at jv.web.jvServlet.doGet(jvServlet.java:71)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
> at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
> at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
> at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
> at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
> at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
> at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)
> at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)
> at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:361)
> at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
> at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
> 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 com.sun.enterprise.util.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:662)
> at jv.ejb.CountrySessionBean.getAllCountries(CountrySessionBean.java:32)
> 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 com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
> at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
> at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
> at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
> at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
> ... 38 more
> Caused by: Exception [TOPLINK-8034] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.EJBQLException
> Exception Description: Error compiling the query [select c from country c]. Unknown abstract schema type [country].
> 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.SelectNode.getClassOfFirstVariable(SelectNode.java:366)
> at oracle.toplink.essentials.internal.parsing.SelectNode.getReferenceClass(SelectNode.java:354)
> at oracle.toplink.essentials.internal.parsing.ParseTree.getReferenceClass(ParseTree.java:463)
> at oracle.toplink.essentials.internal.parsing.ParseTree.adjustReferenceClassForQuery(ParseTree.java:103)
> at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateReadQueryInternal(EJBQLParseTree.java:127)
> at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateQuery(EJBQLParseTree.java:108)
> 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.<init>(EJBQueryImpl.java:114)
> at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:99)
> at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
> at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:204)
> ... 49 more
>
> [/QUOTE]
>
> Please help !!!
> [Message sent by forum member 'meherdadb' (meherdadb)]
>
> http://forums.java.net/jive/thread.jspa?messageID=276504
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>