facebook

Cannot fine new persistence api for EJB3 test

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #230199 Reply

    Murtuza
    Member

    I am trying to write my first EJB3 entity bean based on tutorial from http://docs.jboss.org/ejb3/tutorial/entity/entity.html but MyEclipse does not recognise “javax.persistence.*” and tags like “Entity”, “Table” for code http://docs.jboss.org/ejb3/tutorial/entity/src/org/jboss/tutorial/entity/bean/Order.java.

    I am using Eclipse 3.1 M6 platform with MyEclipse 3.8.4 M6 and J2SDK1.5. I have even configured JBoss as per instructions http://docs.jboss.org/ejb3/tutorial/installing.html. I believe this error is because MyEclipse cannot find new java api. I don’t know where i can find or if its already present in MyEclipse then what is the jar file name. Can anyone help me?

    Thanks in advance.

    #230229 Reply

    Riyad Kalla
    Member

    What kind of file (.java, .jsp, etc.) are you editing when you run into this problem? MyEclipse JSP editor does NOT support JDK 5 annotations yet, but the Eclipse Java Editor in Eclipse 3.1 should recognize them just fine…

    #230296 Reply

    Murtuza
    Member

    I am using MyEclipse Java editor and I am sure the current jre is set to 1.5. Also, what abou the “javax.persistence” imports? why it is not able to resolve these included classes. Do i need to include any library for this?

    Is JDK1.5 is not support fully, does this mean that MyEclipse is not going to be useful to me for any EJB3.0 related testing and development.

    Murtuza

    #230297 Reply

    Murtuza
    Member

    Here is the Order.java file for your reference

    where all import for javax.persistence.* shows error “The import javax.persistence cannot be resolved”

    and Annotation @Entity and @Table shows error “Syntax error, annotations are only available if source level is 1.5”

    package com.kt.test.entity.bean;

    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratorType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Id;
    import javax.persistence.CascadeType;
    import javax.persistence.FetchType;
    import java.util.ArrayList;
    import java.util.Collection;


    @Entity

    @Table(name = “PURCHASE_ORDER”)
    public class Order implements java.io.Serializable
    {
    private int id;
    private double total;
    private Collection<LineItem> lineItems;

    @Id(generate = GeneratorType.AUTO)
    public int getId()
    {
    return id;
    }

    public void setId(int id)
    {
    this.id = id;
    }

    public double getTotal()
    {
    return total;
    }

    public void setTotal(double total)
    {
    this.total = total;
    }

    public void addPurchase(String product, int quantity, double price)
    {
    if (lineItems == null) lineItems = new ArrayList<LineItem>();
    LineItem item = new LineItem();
    item.setOrder(this);
    item.setProduct(product);
    item.setQuantity(quantity);
    item.setSubtotal(quantity * price);
    lineItems.add(item);
    total += quantity * price;
    }

    /*@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy=”order”)
    public Collection<LineItem> getLineItems()
    {
    return lineItems;
    }

    public void setLineItems(Collection<LineItem> lineItems)
    {
    this.lineItems = lineItems;
    }*/
    }

    #230298 Reply

    Riyad Kalla
    Member

    I am using MyEclipse Java editor and I am sure the current jre is set to 1.5. Also, what abou the “javax.persistence” imports? why it is not able to resolve these included classes. Do i need to include any library for this?

    Eclipse JDT provides the Java editor, it is not provided by MyEclipse and yes the 3.1 milestones support JDK 5.

    Also, what abou the “javax.persistence” imports? why it is not able to resolve these included classes. Do i need to include any library for this?

    I have no idea where your javax.persistence package is comming from, this is not part of the standard 5.0 JDK nore is it part of the J2EE 1.4 spec, so these classes are likely specific to whatever app server you are using, in which case you need to find the JAR that provides them and add them to your class path.

    #230399 Reply

    Murtuza
    Member

    Ok I found the resolution, you need to include “jboss-ejb3x.jar” located in <JBOSS_HOME>\server\all\deploy\ejb3.deployer folder. Once this is included you can compile and deploy the appication. If you have the project name ended with .ejb3 then the deployed location in JBoss will automatically have .ejb3 extension.

    #230400 Reply

    Murtuza
    Member

    Hello,

    Npw i have problem deploying the bean. I am using MyEclipse 3.8.4 on Eclipse platform which works fine. I have recently installed and configured “jboss-4.0.2RC1” for EJB3.0. I could successfuly compile and deploy the bean though i cannot find deployed bean in the http://localhost:8080/jmx-console/ but there are no error shown when bean is deployed. When i manually check the files in the deploy folder of the jboss server, the files are present.

    Finally when i try to run the client i get following errors
    Exception in thread “main” javax.naming.NameNotFoundException: com.kt.test.entity.bean.ShoppingCart not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
    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:324)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
    at sun.rmi.transport.Transport$1.run(Transport.java:148)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:534)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at com.kt.test.client.Client.main(Client.java:25)

    Here is hibernate.properties file in the META-INF folder

    hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
    hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
    hibernate.hbm2ddl.auto=create-drop
    #hibernate.hbm2ddl.auto=create
    hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
    # Clustered cache with TreeCache
    #hibernate.cache.provider_class=org.jboss.ejb3.entity.TreeCacheProviderHook
    #hibernate.treecache.mbean.object_name=jboss.cache:service=EJB3EntityTreeCache
    hibernate.connection.datasource=java:/MySqlDS
    hibernate.dialect=org.hibernate.dialect.MySQLDialect

    I have checked and cross checked but could not find where the problem is? I am sure the bean is not correctly deployed since its not listed in the jmx console but there are no error anywhere to see the real problem. Can anyone help on this.

    Thanks in advance

    #230459 Reply

    Murtuza
    Member

    Hello,

    Ok from another forum I found that JBoss4.0.2RC1 does not support EJB3.0 and i should install JBoss4.0.2final. I installed jboss 4.0.2 final and deployed application on the same. Again there are no errors on the JBoss console, a folder with the “.ejb3” in created in the jboss deployed location correctly but the jmx-console still not have the bean listed. Anyways, here are the step for writing (:- copying) this application from the tutorial.

    1. In MyEclipse create new EJB application with name KTEE.ejb3
    2. Create new class for Order, LineItem, ShoppingCart, ShoppingCartBean from the tutorial code.
    3. Deploy on JBoss4.0.2 final with no descriptor file ( as per ejb3 specification there are no deployment descriptor)
    4. The client.java is again from the tutorial.

    When run it throws the same “NameNotFound” exception posted earlier. There are two things i suspect:
    1. A bug in jboss or any step that i m missing somewhere.
    2. Can anyone tell me how to include jndi.properties file in the classpath using MyEclipse for the client.java.

    Here it the log snippet from the JBoss console, there is not much in it as there are no errors thrown.

    09:51:59,738 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/jboss-4.0.2/server/default/deploy/jboss-ha-local-jdbc.rar
    09:52:00,395 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/jboss-4.0.2/server/default/deploy/jboss-ha-xa-jdbc.rar
    09:52:00,863 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/jboss-4.0.2/server/default/deploy/jboss-local-jdbc.rar
    09:52:01,379 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/jboss-4.0.2/server/default/deploy/jboss-xa-jdbc.rar
    09:52:01,848 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/jboss-4.0.2/server/default/deploy/jms/jms-ra.rar
    09:52:02,363 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/jboss-4.0.2/server/default/deploy/mail-ra.rar
    09:52:06,770 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager ‘jboss.jca:service=DataSourceBinding,name=DefaultDS to JNDI name ‘java:DefaultDS’
    09:52:08,082 INFO [A] Bound to JNDI name: queue/A
    09:52:08,082 INFO [B] Bound to JNDI name: queue/B
    09:52:08,082 INFO [C] Bound to JNDI name: queue/C
    09:52:08,098 INFO [D] Bound to JNDI name: queue/D
    09:52:08,098 INFO [ex] Bound to JNDI name: queue/ex
    09:52:08,238 INFO [testTopic] Bound to JNDI name: topic/testTopic
    09:52:08,238 INFO [securedTopic] Bound to JNDI name: topic/securedTopic
    09:52:08,270 INFO [testDurableTopic] Bound to JNDI name: topic/testDurableTopic
    09:52:08,285 INFO [testQueue] Bound to JNDI name: queue/testQueue
    09:52:08,488 INFO [UILServerILService] JBossMQ UIL service available at : /0.0.0.0:8093
    09:52:08,738 INFO [DLQ] Bound to JNDI name: queue/DLQ
    09:52:09,832 INFO [ConnectionFactoryBindingService] Bound connection factory for resource adapter for ConnectionManager ‘jboss.jca:service=ConnectionFactoryBinding,name=JmsXA to JNDI name ‘java:JmsXA’
    09:52:10,457 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager ‘jboss.jca:service=DataSourceBinding,name=MySqlDS to JNDI name ‘java:MySqlDS’
    09:52:10,660 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=file:/D:/jboss-4.0.2/server/default/deploy/jmx-console.war/
    09:52:12,504 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
    09:52:13,926 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009
    09:52:14,192 INFO [JkMain] Jk running ID=0 time=0/1079 config=null
    09:52:14,238 INFO [Server] JBoss (MX MicroKernel) [4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)] Started in 1m:5s:687ms

    Can anyone help on this soon.

    Thanks in advance.

    #230470 Reply

    Riyad Kalla
    Member

    You’re questions are now into the EJB3/JBoss scope of focus and unfortunately this is not a topic I can help with. I would encourage some of our other EJB3 gurus to answer if they can. Good luck!

    #230504 Reply

    Murtuza
    Member

    OK, but can you tell me how to include jndi.properties file in the classpath using MyEclipse for the client.java to set System Properties like we do from command line with “-D” options.

    Murtuza

    #230509 Reply

    Riyad Kalla
    Member

    Murtuza,
    You can include the jndi.properties file either in the root of your source package OR you can modify the app server’s classpath (Window > Preferences > MyEclipse > Application Server > JBoss 4 > Paths > “Append to Classpath” > “Add”).

    #230634 Reply

    Murtuza
    Member

    The jndi.properties file is not for the JBoss application server. This file has to be included to the client application. I have written a test client file “Client.jar” which has following code:

    public class Client
    {
    public static void main(String[] args) throws Exception
    {
    SecurityManager security = System.getSecurityManager();
    InitialContext ctx = new InitialContext();
    ShoppingCart cart = (ShoppingCart) ctx.lookup(ShoppingCart.class.getName());

    System.out.println(“Buying 2 memory sticks”);
    cart.buy(“Memory stick”, 2, 500.00);
    System.out.println(“Buying a laptop”);
    cart.buy(“Laptop”, 1, 2000.00);

    System.out.println(“Print cart:”);
    Order order = cart.getOrder();
    System.out.println(“Total: $” + order.getTotal());
    for (LineItem item : order.getLineItems())
    {
    System.out.println(item.getQuantity() + ” ” + item.getProduct() + ” ” + item.getSubtotal());
    }

    System.out.println(“Checkout”);
    cart.checkout();

    }
    }

    When i run this client, i get following errors

    Exception in thread “main” javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.init(Unknown Source)
    at javax.naming.InitialContext.<init>(Unknown Source)
    at com.kt.test.order.Client.main(Client.java:20)
    Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
    … 5 more

    From the JBoss forum i understand that i have to include jndi.properties file in the classpath. This property file is already placed at the root of the project. I suppose this is already in the classpath but how can i make sure. How do i manually specify it.

    Thanks in advance.

    Murtuza

    #230654 Reply

    Riyad Kalla
    Member

    Murtuza,
    From your exception it seems fairly clear that your org.jnp.interfaces.NamingContextFactory class is not being included in the classpath for the Client, I don’t know where this class comes from (likely a class your company uses), but you will want to add that to your Java Build Path for the client to run appropriately.

    #230690 Reply

    Murtuza
    Member

    Thanks, i found the resolution from JBoss forum. Anyone facing similar problems refer to this link

    http://www.jboss.org/index.html?module=bb&op=viewtopic&t=57223

Viewing 14 posts - 1 through 14 (of 14 total)
Reply To: Cannot fine new persistence api for EJB3 test

You must be logged in to post in the forum log in